E-mail REST API Samples
Overview
The following is a sample code snippet for an e-mail interaction using the REST API of the Web API Server.
Send E-mail Interaction
[+] Sample
FormDataMultiPart formDataMultiPart = new FormDataMultiPart();
formDataMultiPart.field("firstName", "First");
formDataMultiPart.field("lastName", "Last");
formDataMultiPart.field("tenantName", "Environment");
formDataMultiPart.field("fromAddress", "from@address");
formDataMultiPart.field("subject", "subject");
formDataMultiPart.field("text", "very long email body");
final String value1 = "Hello World!";
FormDataContentDisposition dispo = FormDataContentDisposition.name("files").fileName("test.txt").size(value1.getBytes().length).build();
FormDataBodyPart bodyPart = new FormDataBodyPart(dispo, value1);
formDataMultiPart.bodyPart(bodyPart);
final String value2 = "Goodbye World!";
dispo = FormDataContentDisposition.name("files").fileName("test2.txt").size(value2.getBytes().length).build();
bodyPart = new FormDataBodyPart(dispo, value2);
formDataMultiPart.bodyPart(bodyPart);
Client client = new Client();
WebResource webResource = client.resource("http://localhost:8080/webapi/api/v2/emails");
ClientResponse response = webResource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, formDataMultiPart);
if (response.getStatus() != 200)
{
throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}
String json = response.getEntity(String.class);