Skip to content

Messages

Igor Balos edited this page Nov 13, 2017 · 7 revisions

Retrieveing sent or processed email details is easy. All you need to do is create a message you plan to send and send it with API client.

Here are couple of simple sending examples.

Message message = new Message("[email protected]", "[email protected]", "Hello world simple", "Hello body");
message.setReplyTo("[email protected]");

// Deliver a simple message
MessageResponse response = client.deliverMessage(message);

Deliver messages with tags.

message = new Message("[email protected]", "[email protected]", "Hello world with tag", "Hello body");
message.setTag("testTag");

// Deliver a simple message with tag
response = client.deliverMessage(message);

You can enable open and click tracking super easy too. Check out the example below.

String htmlMessage = "<!DOCTYPE html><html><body>" +
"<p>Hello<a href=\"http://www.google.com\">world</a></p></body></html>";

message = new Message("[email protected]", "[email protected]", "Hello world - opens and clicks", htmlMessage);
message.setTrackOpens(true);
message.setTrackLinks(Message.TRACK_LINKS.HtmlAndText);

// Deliver a simple message with click and open tracking
response = client.deliverMessage(message);

In order to send emails with attachments, all you need to do is add attachment with specifying path where its located in your message.

message = new Message("[email protected]", "[email protected]", "Hello world - attachment", "Hello body");
message.addAttachment("/Users/bash/Documents/Temp/test.rb");
response = client.deliverMessage(message);
// Deliver message with attachments

You can add custom headers in two easy ways. Check them out in the example.

message = new Message("[email protected]", "[email protected]", "Hello world - headers", "Hello body");

ArrayList<Header> headers = new ArrayList<>();
headers.add(new Header("TEST", "CUSTOM HEADER"));
message.setHeaders(headers);

message.addHeader("TEST2", "CUSTOM HEADER2");
response = client.deliverMessage(message);

Sending email to many recipients and include their full names too.

message = new Message("[email protected]", "[email protected]", "Hello world - recipients", "Hello body");

HashMap<String, String> to = new HashMap<>();
to.put("John Smith", "[email protected]");
to.put("Igor Smith", "[email protected]");
HashMap<String, String> cc = new HashMap<>();
cc.put("Igor Smith", "[email protected]");
message.setTo(to);
message.setCc(cc);

// Deliver message with full name recipients
response = client.deliverMessage(message);
message = new Message("[email protected]", "[email protected]", "Hello world - recipients", "Hello body");

ArrayList<String> to = new ArrayList<>();
to.add("[email protected]");
to.add("[email protected]");
message.setTo(to);

// Deliver message with array of recipients
response = client.deliverMessage(message);

The library also allows you to send emails as batches. This allows you to send many emails at once. All you need to do is specify an array of messages you plan to send and send them.

ArrayList<Message> messages = new ArrayList<>();
messages.add(new Message("[email protected]", "[email protected]", "Hello world - message one", "Hello body"));
messages.add(new Message("[email protected]", "[email protected]", "Hello world - message two", "Hello body"));

// Deliver messages by batch
ArrayList<MessageResponse> response = client.deliverMessage(messages);