Skip to content

Email sending

Igor Balos edited this page Nov 9, 2017 · 24 revisions

With Postmark you can send email super easy. Before diving into this chapter, make sure you have checked out our getting started page.

To send a simple email, all you need is to create a mail message object, retrieve Postmark API client and send the message. You can validate the message by validating result of MessageResponse class.

Deliver a simple message

String htmlBody = "<!DOCTYPE html><html><body>" +
"<p>Hello<a href=\"http://www.google.com\">world</a></p></body></html>";
        
// create a simple email message
Message message = new Message("[email protected]", "[email protected]", "Hello from Postmark!", htmlBody);
message.setReplyTo("[email protected]");

// Deliver a simple message
ApiClient client = Postmark.getApiClient(<server token>);
MessageResponse response = client.deliverMessage(message);
System.out.println(response.getMessage());

Sending a message with tag

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

Sending a message with open tracking enabled

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

Message message = new Message("[email protected]", "[email protected]", "Hello Postmark!", htmlBody);
message.setTrackOpens(true);
client.deliverMessage(message);

Sending a message with link tracking enabled

Message message = new Message("[email protected]", "[email protected]", "Hello Postmark!", htmlBody);

// set tracking type, it can be Message.TRACK_LINKS.Html, Message.TRACK_LINKS.Html or Message.TRACK_LINKS.HtmlAndText
message.setTrackLinks(Message.TRACK_LINKS.HtmlAndText);
client.deliverMessage(message);