|
1 | | -Aspose.Email Cloud is a REST API for creating email archiving applications that work with common email file formats. It lets developers manipulate message formats such as Outlook MSG, EML and MHT files. |
| 1 | +Aspose.Email Cloud is a REST API for creating email applications that work with standard email file formats. This SDK: |
| 2 | +- Lets developers manipulate different emails’ formats such as Outlook MSG, EML, VCard, and iCalendar files |
| 3 | +- Has a built-in email client |
| 4 | +- Supports AI functionalities: |
| 5 | + - The Business card recognition |
| 6 | + - The Name API for parsing and handling personal names |
2 | 7 |
|
3 | | -To use these SDKs, you will need App SID and App Key which can be looked up at [Aspose Cloud Dashboard](https://dashboard.aspose.cloud/#/apps) (free registration in Aspose Cloud is required for this). |
| 8 | +To use this SDK, you need an App SID and an App Key; they can be looked up at [Aspose Cloud Dashboard](https://dashboard.aspose.cloud/#/apps) (it requires free registration in Aspose Cloud for this). |
4 | 9 |
|
5 | 10 | ## How to use the SDK? |
6 | | -The complete source code is available in the GIT repository. You can either directly use it in your project via source code or get [nmpjs distribution](https://www.npmjs.com/package/@asposecloud/aspose-email-cloud) (recommended). |
| 11 | +The complete source code is available in the GIT repository. |
7 | 12 |
|
8 | | -### Install Aspose.Email for Cloud via NPM |
| 13 | +### Usage examples |
| 14 | +To use the API, you should create an EmailApi object: |
| 15 | +```typescript |
| 16 | +var appKey = "Your App Key"; |
| 17 | +var appSid = "Your App SID"; |
| 18 | +var api = new EmailApi(appSid, appKey); |
| 19 | +``` |
| 20 | + |
| 21 | +#### Business cards recognition API |
| 22 | +See examples below: |
| 23 | + |
| 24 | +<details open> |
| 25 | + <summary>Parse business card images to VCard contact files</summary> |
| 26 | + |
| 27 | +```typescript |
| 28 | +var folder = 'some/folder/on/storage'; |
| 29 | +var storage = 'First Storage'; //Your storage name |
| 30 | +var imageData = fs.readFileSync('some/business/card/image/file/on/disk'); |
| 31 | +var storageFileName = 'someFileName.png'; //Supports different image formats: PNG, JPEG, BMP, TIFF, GIF, etc. |
| 32 | +// Upload business card image to storage |
| 33 | +await api.uploadFile(new requests.UploadFileRequest(folder + '/' + storageFileName, imageData, storage)); |
| 34 | +var outFolder = 'some/other/folder/on/storage'; //Business card recognition results will be saved here |
| 35 | +await api.createFolder(new requests.CreateFolderRequest(outFolder, storage)); |
| 36 | +// Call business card recognition action |
| 37 | +var result = await api.aiBcrParseStorage( |
| 38 | + new requests.AiBcrParseStorageRequest(new models.AiBcrParseStorageRq( |
| 39 | + null, |
| 40 | + [new models.AiBcrImageStorageFile( //We can process multiple images in one request |
| 41 | + true, //the image contains only one business card (you can upload image with multiple cards on it) |
| 42 | + new models.StorageFileLocation(storage, folder, storageFileName))], |
| 43 | + new models.StorageFolderLocation(storage, outFolder)))); |
| 44 | +// Get file name from recognition result |
| 45 | +var contactFile = result.body.value[0]; //result.body.value can contain multiple files, if we sent multicard images or multiple images |
| 46 | +// You can download the VCard file, which produced by the recognition method ... |
| 47 | +var contactBinary = await api.downloadFile(new requests.DownloadFileRequest( |
| 48 | + contactFile.folderPath + '/' + contactFile.fileName, storage)); |
| 49 | +// ... and print it to console |
| 50 | +console.log(contactBinary.body.toString()); |
| 51 | +// Also, you can get VCard object properties’ list using Contact API |
| 52 | +var contactProperties = await api.getContactProperties(new requests.GetContactPropertiesRequest( |
| 53 | + 'vcard', contactFile.fileName, contactFile.folderPath, contactFile.storage)); |
| 54 | +//All VCard’s properties are available as a list. Complex properties are represented as hierarchical structures. |
| 55 | +//Let's print all primitive properties’ values: |
| 56 | +contactProperties.body.internalProperties |
| 57 | + .filter(property => property.type == 'PrimitiveObject') |
| 58 | + .map(property => property as models.PrimitiveObject) |
| 59 | + .forEach(property => |
| 60 | + console.log('Property name:' + property.name + ' value:' + property.value)); |
| 61 | +``` |
| 62 | +</details> |
| 63 | + |
| 64 | +<details> |
| 65 | + <summary>Parse images directly, without the using of a storage</summary> |
| 66 | + |
| 67 | +```typescript |
| 68 | +//Read image from file and convert it to Base64 string |
| 69 | +var imageData = fs.readFileSync('some/business/card/image/file/on/disk').toString('base64'); |
| 70 | +var result = await api.aiBcrParse(new requests.AiBcrParseRequest( |
| 71 | + new models.AiBcrBase64Rq(undefined, [new models.AiBcrBase64Image(true, imageData)]))); |
| 72 | +//Result contains all recognized VCard objects (only the one in our case) |
| 73 | +var contactProperties = result.body.value[0]; |
| 74 | +//VCard object is available as a list of properties, without any external calls: |
| 75 | +contactProperties.internalProperties |
| 76 | + .filter(property => property.type == 'PrimitiveObject') |
| 77 | + .map(property => property as models.PrimitiveObject) |
| 78 | + .forEach(property => |
| 79 | + console.log('Property name:' + property.name + ' value:' + property.value)); |
| 80 | +``` |
| 81 | +</details> |
| 82 | + |
| 83 | +#### Name API |
| 84 | +See examples below: |
| 85 | +<details open> |
| 86 | + <summary>Detect a person's gender by name</summary> |
| 87 | + |
| 88 | +```typescript |
| 89 | +var result = await api.aiNameGenderize(new requests.AiNameGenderizeRequest('John Cane')); |
| 90 | +//the result contains a list of hypothesis about a person's gender. |
| 91 | +//all hypothesis include score, so you can use the most scored version, which will be the first in a list: |
| 92 | +console.log(result.body.value[0].gender); //prints 'Male' |
| 93 | +``` |
| 94 | +</details> |
| 95 | + |
| 96 | +<details> |
| 97 | + <summary>Format person's name using defined format</summary> |
| 98 | + |
| 99 | +```typescript |
| 100 | +var result = await api.aiNameFormat(new requests.AiNameFormatRequest( |
| 101 | + 'Mr. John Michael Cane', undefined, undefined, undefined, undefined, '%t%L%f%m')); |
| 102 | +console.log(result.body.name); //prints 'Mr. Cane J. M.' |
| 103 | +``` |
| 104 | +</details> |
9 | 105 |
|
| 106 | +<details> |
| 107 | + <summary>Compare the names to find out if they belong to the same person or not</summary> |
| 108 | + |
| 109 | +```typescript |
| 110 | +var first = 'John Michael Cane'; |
| 111 | +var second = 'Cane J.'; |
| 112 | +var result = await api.aiNameMatch(new requests.AiNameMatchRequest( |
| 113 | + first, second)); |
| 114 | +console.log(result.body.similarity > 0.5); //prints 'true', names look similar |
| 115 | +``` |
| 116 | +</details> |
| 117 | + |
| 118 | +<details> |
| 119 | + <summary>Expand a person's name into a list of possible alternatives</summary> |
| 120 | + |
| 121 | +```typescript |
| 122 | +var result = await api.aiNameExpand(new requests.AiNameExpandRequest( |
| 123 | + 'Smith Bobby')); |
| 124 | +var names = result.body.names |
| 125 | + .map(weighted => weighted.name) |
| 126 | + .forEach(name => console.log(name)); //prints 'Mr. Smith', 'B. Smith', etc. |
| 127 | +``` |
| 128 | +</details> |
| 129 | + |
| 130 | +<details> |
| 131 | + <summary>Get k most probable names for given starting characters</summary> |
| 132 | + |
| 133 | +```typescript |
| 134 | +var prefix = 'Dav'; |
| 135 | +var result = await api.aiNameComplete(new requests.AiNameCompleteRequest( |
| 136 | + prefix)); |
| 137 | +var names = result.body.names |
| 138 | + .map(weighted => prefix + weighted.name) |
| 139 | + .forEach(name => console.log(name)); //prints 'David', 'Dave', 'Davis', etc. |
| 140 | +``` |
| 141 | +</details> |
| 142 | + |
| 143 | +<details> |
| 144 | + <summary>Parse out a person's name from an email address.</summary> |
| 145 | + |
| 146 | +```typescript |
| 147 | +var result = await api.aiNameParseEmailAddress(new requests.AiNameParseEmailAddressRequest( |
| 148 | + 'john-cane@gmail.com')); |
| 149 | +var extractedValues = result.body.value |
| 150 | + .map(extracted => extracted.name) |
| 151 | + .reduce((accumulator, value) => accumulator.concat(value)); |
| 152 | +var givenName = extractedValues.find(extracted => extracted.category == 'GivenName'); |
| 153 | +var surname = extractedValues.find(extracted => extracted.category == 'Surname'); |
| 154 | +console.log(givenName.value); // 'John' |
| 155 | +console.log(surname.value); // 'Cane' |
| 156 | +``` |
| 157 | +</details> |
| 158 | + |
| 159 | +### Install Aspose.Email for Cloud via NPM |
| 160 | +You can use it directly in your project via the source code or get a [npm package](https://www.npmjs.com/package/@asposecloud/aspose-email-cloud) |
10 | 161 | From the command line: |
11 | 162 |
|
12 | 163 | npm install @asposecloud/aspose-email-cloud --save |
13 | 164 |
|
14 | 165 | # Licensing |
15 | | -All Aspose.Email for Cloud SDKs, helper scripts and templates are licensed under [MIT License](LICENSE). |
| 166 | +All Aspose.Email Cloud SDKs, helper scripts and templates are licensed under [MIT License](LICENSE). |
16 | 167 |
|
17 | 168 | # Resources |
18 | 169 | + [**Website**](https://www.aspose.cloud) |
|
0 commit comments