|
1 | | -Aspose.Email Cloud is a REST API for creating email 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 SDK for Java [](https://repository.aspose.cloud/repo/com/aspose/aspose-email-cloud/) [](https://repository.aspose.cloud/repo/com/aspose/aspose-email-cloud/) |
| 2 | +This repository contains Aspose.Email Cloud SDK for Java source code. This SDK allows you to work with Aspose.Email Cloud REST APIs in your Java applications quickly and easily, with zero initial cost. |
| 3 | + |
| 4 | +[Aspose.Email Cloud home](https://products.aspose.cloud/email/family "Aspose.Email Cloud") |
| 5 | +[API Reference](https://apireference.aspose.cloud/email/) |
| 6 | + |
| 7 | + |
2 | 8 |
|
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). |
4 | 9 |
|
5 | 10 | ## How to use the SDK? |
6 | | -The complete source code is available in the GIT repository. |
| 11 | +The complete source code is available in the GIT repository. |
| 12 | + |
| 13 | +Use reference documentation, available [**here**](docs/README.md) |
| 14 | + |
| 15 | +### Prerequisites |
| 16 | +To use these 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). |
| 17 | + |
| 18 | +### Installation |
| 19 | +You can either directly use it in your project via jar file or add it as Maven dependency ([see repo](https://repository.aspose.cloud/repo/com/aspose/aspose-email-cloud/)): |
| 20 | + |
| 21 | +First, you should add a repository: |
| 22 | +```xml |
| 23 | +<repository> |
| 24 | + <id>aspose-cloud</id> |
| 25 | + <name>Aspose.Cloud repository</name> |
| 26 | + <url>https://repository.aspose.cloud</url> |
| 27 | +</repository> |
| 28 | +``` |
| 29 | +Then, add a dependency: |
| 30 | +```xml |
| 31 | +<dependency> |
| 32 | + <groupId>com.aspose</groupId> |
| 33 | + <artifactId>aspose-email-cloud</artifactId> |
| 34 | +</dependency> |
| 35 | +``` |
| 36 | + |
| 37 | +### Usage examples |
| 38 | +To use the API, you should create an EmailApi object: |
| 39 | +```java |
| 40 | +EmailApi api = new EmailApi("Your App Key", "Your App SID"); |
| 41 | +``` |
| 42 | + |
| 43 | +#### Business cards recognition API |
| 44 | +See examples below: |
| 45 | + |
| 46 | +<details open> |
| 47 | + <summary>Parse business card images to VCard contact files</summary> |
| 48 | + |
| 49 | +```java |
| 50 | +// Upload business card image to storage |
| 51 | +String storage = "First Storage"; //Your storage name |
| 52 | +String fileName = "someFileName.png"; //Supports different image formats: PNG, JPEG, BMP, TIFF, GIF, etc. |
| 53 | +String folder = "some/folder/path/on/storage"; |
| 54 | +String filePath = folder + "/" + fileName; |
| 55 | +byte[] fileBytes = IOUtils.toByteArray( |
| 56 | + new FileInputStream("some/business/card/image/on/disk.png")); |
| 57 | +api.uploadFile(new UploadFileRequestData( |
| 58 | + filePath, |
| 59 | + fileBytes, |
| 60 | + storage)); |
| 61 | +String outFolderPath = "some/other/folder/path/on/storage"; //Business card recognition results will be saved here |
| 62 | +api.createFolder(new CreateFolderRequestData(outFolderPath, storage)); |
| 63 | +// Call business card recognition action |
| 64 | +ListResponseOfStorageFileLocation result = api.aiBcrParseStorage(new AiBcrParseStorageRequestData( |
| 65 | + new AiBcrParseStorageRq( |
| 66 | + null, |
| 67 | + //We can process multiple images in one request |
| 68 | + Arrays.asList(new AiBcrImageStorageFile( |
| 69 | + true, //Flag isSingle determines that image contains single VCard or more. |
| 70 | + //Only single VCard on image variant is supported in current version. |
| 71 | + new StorageFileLocation(storage, folder, fileName))), |
| 72 | + new StorageFolderLocation(storage, outFolderPath)))); |
| 73 | +// Get file name from recognition result |
| 74 | +StorageFileLocation contactFile = result.getValue().get(0); //result.getValue() can contain multiple files, if we sent multicard images or multiple images |
| 75 | +// You can download the VCard file, which produced by the recognition method ... |
| 76 | +byte[] contactBytes = api.downloadFile(new DownloadFileRequestData( |
| 77 | + contactFile.getFolderPath() + "/" + contactFile.getFileName(), |
| 78 | + contactFile.getStorage(), |
| 79 | + null)); |
| 80 | +String contactFileContent = new String(contactBytes, StandardCharsets.UTF_8); |
| 81 | +//... and print it |
| 82 | +System.out.println(contactFileContent); |
| 83 | +// Also, you can get VCard object properties’ list using Contact API |
| 84 | +HierarchicalObject contactProperties = api.getContactProperties( |
| 85 | + new GetContactPropertiesRequestData( |
| 86 | + "VCard", |
| 87 | + contactFile.getFileName(), |
| 88 | + contactFile.getFolderPath(), |
| 89 | + contactFile.getStorage())); |
| 90 | +//All VCard’s properties are available as a list. Complex properties are represented as hierarchical structures. |
| 91 | +//Let's print all primitive properties’ values: |
| 92 | +for (BaseObject property: contactProperties.getInternalProperties()) { |
| 93 | + if (property.getType().equals("PrimitiveObject")) { |
| 94 | + PrimitiveObject primitive = (PrimitiveObject)property; |
| 95 | + System.out.println("Property name: " + |
| 96 | + primitive.getName() + |
| 97 | + " value: " + |
| 98 | + primitive.getValue()); |
| 99 | + } |
| 100 | +} |
| 101 | +``` |
| 102 | +</details> |
| 103 | + |
| 104 | + |
| 105 | +<details> |
| 106 | + <summary>Parse images directly, without the using of a storage</summary> |
| 107 | + |
| 108 | +```java |
| 109 | +//Read image from file and convert it to Base64 string |
| 110 | +byte[] fileBytes = IOUtils.toByteArray( |
| 111 | + new FileInputStream("some/business/card/image/on/disk.png")); |
| 112 | +String fileBase64 = Base64.encodeToString(fileBytes, false); |
| 113 | +ListResponseOfHierarchicalObject result = api.aiBcrParse(new AiBcrParseRequestData( |
| 114 | + new AiBcrBase64Rq(null, Arrays.asList(new AiBcrBase64Image(true, fileBase64))))); |
| 115 | +//Result contains all recognized VCard objects (only the one in our case) |
| 116 | +HierarchicalObject contactProperties = result.getValue().get(0); |
| 117 | +//VCard object is available as a list of properties, without any external calls: |
| 118 | +for (BaseObject property: contactProperties.getInternalProperties()) { |
| 119 | + if (property.getType().equals("PrimitiveObject")) { |
| 120 | + PrimitiveObject primitive = (PrimitiveObject)property; |
| 121 | + System.out.println("Property name: " + |
| 122 | + primitive.getName() + |
| 123 | + " value: " + |
| 124 | + primitive.getValue()); |
| 125 | + } |
| 126 | +} |
| 127 | +``` |
| 128 | +</details> |
| 129 | + |
| 130 | + |
| 131 | +#### Name API |
| 132 | +See examples below: |
| 133 | +<details open> |
| 134 | + <summary>Detect a person's gender by name</summary> |
| 135 | + |
| 136 | +```java |
| 137 | +ListResponseOfAiNameGenderHypothesis result = api |
| 138 | + .aiNameGenderize(new AiNameGenderizeRequestData("John Cane", null, null, null, null, null)); |
| 139 | +// the result contains a list of hypothesis about a person's gender. |
| 140 | +// all hypothesis include score, so you can use the most scored version, |
| 141 | +// which will be the first in a list: |
| 142 | +System.out.println(result.getValue().get(0).getGender()); //prints "Male" |
| 143 | +``` |
| 144 | +</details> |
| 145 | + |
| 146 | +<details> |
| 147 | + <summary>Format person's name using defined format</summary> |
| 148 | + |
| 149 | +```java |
| 150 | +AiNameFormatted result = api.aiNameFormat( |
| 151 | + new AiNameFormatRequestData("Mr. John Michael Cane", null, null, null, null, "%t%L%f%m", null)); |
| 152 | +System.out.println(result.getName()) // prints "Mr. Cane J. M." |
| 153 | +``` |
| 154 | +</details> |
| 155 | + |
| 156 | +<details> |
| 157 | + <summary>Compare the names to find out if they belong to the same person or not</summary> |
| 158 | + |
| 159 | +```java |
| 160 | +final String first = "John Michael Cane"; |
| 161 | +final String second = "Cane J."; |
| 162 | +AiNameMatchResult result = api |
| 163 | + .aiNameMatch(new AiNameMatchRequestData(first, second, null, null, null, null, null)); |
| 164 | +System.out.println(result.getSimilarity() >= 0.5); //prints "true", names look similar |
| 165 | +``` |
| 166 | +</details> |
| 167 | + |
| 168 | +<details> |
| 169 | + <summary>Expand a person's name into a list of possible alternatives</summary> |
| 170 | + |
| 171 | + |
| 172 | +```java |
| 173 | +String name = "Smith Bobby"; |
| 174 | +AiNameWeightedVariants result = api |
| 175 | + .aiNameExpand(new AiNameExpandRequestData(name, null, null, null, null, null)); |
| 176 | +for (AiNameWeighted weighted : result.getNames()) { |
| 177 | + System.out.println(weighted.getName()); //prints "Mr. Smith", "B. Smith", etc. |
| 178 | +} |
| 179 | +``` |
| 180 | +</details> |
| 181 | + |
| 182 | +<details> |
| 183 | + <summary>Get k most probable names for given starting characters</summary> |
| 184 | + |
| 185 | +```java |
| 186 | +String prefix = "Dav"; |
| 187 | +AiNameWeightedVariants result = api |
| 188 | + .aiNameComplete(new AiNameCompleteRequestData(prefix, null, null, null, null, null)); |
| 189 | +for (AiNameWeighted weighted : result.getNames()) { |
| 190 | + System.out.println(prefix + weighted.getName()); //prints "David", "Dave", "Davis", etc. |
| 191 | +} |
| 192 | +``` |
| 193 | +</details> |
| 194 | + |
| 195 | +<details> |
| 196 | + <summary>Parse out a person's name from an email address.</summary> |
7 | 197 |
|
8 | | -### Install Aspose.Email for Cloud |
9 | | -You can either directly use it in your project via jar file or add it as Maven dependency. |
| 198 | +```java |
| 199 | +String address = "john-cane@gmail.com"; |
| 200 | +ListResponseOfAiNameExtracted result = api |
| 201 | + .aiNameParseEmailAddress(new AiNameParseEmailAddressRequestData(address, null, null, null, null, null)); |
| 202 | +String givenName = null; |
| 203 | +String surname = null; |
| 204 | +for(AiNameExtracted extracted: result.getValue()) { |
| 205 | + for(AiNameExtractedComponent component: extracted.getName()) { |
| 206 | + if (component.getCategory().equals("GivenName")) { |
| 207 | + givenName = component.getValue(); |
| 208 | + } |
| 209 | + if (component.getCategory().equals("Surname")) { |
| 210 | + surname = component.getValue(); |
| 211 | + } |
| 212 | + } |
| 213 | +} |
| 214 | +System.out.println("Given name is " + givenName); // "John" |
| 215 | +System.out.println("Surname is " + surname); // "Cane" |
| 216 | +``` |
| 217 | +</details> |
10 | 218 |
|
11 | 219 | # Licensing |
12 | 220 | All Aspose.Email for Cloud SDKs, helper scripts and templates are licensed under [MIT License](LICENSE). |
|
0 commit comments