Skip to content

Commit

Permalink
added support for sending per message stream and inline attachment su…
Browse files Browse the repository at this point in the history
…pport for templates
  • Loading branch information
ibalosh committed Mar 17, 2020
1 parent 8bd6308 commit b54a830
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</developers>

<properties>
<postmark.version>1.5.0</postmark.version>
<postmark.version>1.5.2</postmark.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<jackson.minimum.version>2.9.7</jackson.minimum.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Base email message object
*/
public class BaseMessage {
private String messageStream;
private String from;
private String to;
private String cc;
Expand Down Expand Up @@ -45,8 +46,26 @@ public BaseMessage(String from, String to, String subject, String htmlBody, Stri
this.attachments = new ArrayList<>();
}

public BaseMessage(String from, String to, String subject, String htmlBody, String textBody, String messageStream) {
this.from = from;
this.to = to;
this.subject = subject;
this.htmlBody = htmlBody;
this.textBody = textBody;
this.messageStream = messageStream;
this.attachments = new ArrayList<>();
}

// SETTERS AND GETTERS

public String getMessageStream() {
return messageStream;
}

public void setMessageStream(String messageStream) {
this.messageStream = messageStream;
}

public String getFrom() {
return from;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public Message(String from, String to, String subject, String htmlBody, String t
super(from, to, subject, htmlBody, textBody);
}

public Message(String from, String to, String subject, String htmlBody, String textBody, String messageStream) {
super(from, to, subject, htmlBody, textBody, messageStream);
}

// SETTERS AND GETTERS

public Boolean getTrackOpens() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class BaseTemplatedMessage {
private Integer templateId;
private String templateAlias;
private Object templateModel;
private String messageStream;
private Boolean inlineCss;
private String from;
private String to;
Expand All @@ -39,16 +40,47 @@ public BaseTemplatedMessage(String from, String to) {
this.to = to;
}

public BaseTemplatedMessage(String from, String to, String templateAlias) {
this();
this.from = from;
this.to = to;
this.templateAlias = templateAlias;
}

public BaseTemplatedMessage(String from, String to, String templateAlias, String messageStream) {
this();
this.from = from;
this.to = to;
this.templateAlias = templateAlias;
this.messageStream = messageStream;
}

public BaseTemplatedMessage(String from, String to, Integer templateId) {
this();
this.from = from;
this.to = to;
this.templateId = templateId;
}

public BaseTemplatedMessage(String from, String to, Integer templateId, String messageStream) {
this();
this.from = from;
this.to = to;
this.templateId = templateId;
this.messageStream = messageStream;
}


// SETTERS AND GETTERS

public String getMessageStream() {
return messageStream;
}

public void setMessageStream(String messageStream) {
this.messageStream = messageStream;
}

public String getTemplateAlias() { return templateAlias; }

public void setTemplateAlias(String templateAlias) { this.templateAlias = templateAlias; }
Expand Down Expand Up @@ -193,6 +225,28 @@ public void addAttachment(String path) throws IOException {
addAttachment(new File(path).getName(), readFileContent(path), readFileContentType(path));
}

/**
* Add attachments from file path with content id. Easiest way to add inline image attachments.
*
* @param path file path
* @param contentId file content id, like "cid:image.jpg", very usefull for inline images
*/
public void addAttachment(String path, String contentId) throws IOException {
addAttachment(new File(path).getName(), readFileContent(path), readFileContentType(path), contentId);
}

/**
* Add attachments by file details
*
* @param filename filename to show up in email
* @param content file content
* @param contentType file content type
* @param contentId file content id
*/
public void addAttachment(String filename, String content, String contentType, String contentId) {
addAttachment(filename, content.getBytes(),contentType, contentId);
}

/**
* Add attachments by file details
*
Expand Down Expand Up @@ -220,6 +274,24 @@ public void addAttachment(String name, byte[] content, String contentType) {
addAttachment(attachment);
}

/**
* Add attachments by file details
*
* @param name filename to show up in email
* @param content file content
* @param contentType file content type
* @param contentId file content id, like "cid:image.jpg", very usefull for inline images
*/
public void addAttachment(String name, byte[] content, String contentType, String contentId) {
Map<String, String> attachment = new HashMap<>();
attachment.put("Name", name);
attachment.put("Content", Base64.getEncoder().encodeToString(content));
attachment.put("ContentType", contentType);
attachment.put("ContentId", contentId);

addAttachment(attachment);
}

/**
* Add attachments as hash. To add it, attachment needs to look like this:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ public TemplatedMessage(String from, String to, Integer templateId) {
super(from, to, templateId);
}

public TemplatedMessage(String from, String to, String templateAlias) {
super(from, to, templateAlias);
}

public TemplatedMessage(String from, String to, String templateAlias, String messageStream) {
super(from, to, templateAlias, messageStream);
}

public TemplatedMessage(String from, String to, Integer templateId, String messageStream) {
super(from, to, templateId, messageStream);
}

// SETTERS AND GETTERS

public Boolean getTrackOpens() { return trackOpens; }
Expand Down

0 comments on commit b54a830

Please sign in to comment.