From b54a830f1013ef3b2887d18e81853dde265cba20 Mon Sep 17 00:00:00 2001 From: Igor Balos Date: Tue, 17 Mar 2020 17:11:45 +0100 Subject: [PATCH] added support for sending per message stream and inline attachment support for templates --- pom.xml | 2 +- .../data/model/message/BaseMessage.java | 19 +++++ .../client/data/model/message/Message.java | 4 ++ .../model/templates/BaseTemplatedMessage.java | 72 +++++++++++++++++++ .../model/templates/TemplatedMessage.java | 12 ++++ 5 files changed, 108 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3b765fa..92eb011 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ - 1.5.0 + 1.5.2 UTF-8 1.8 2.9.7 diff --git a/src/main/java/com/wildbit/java/postmark/client/data/model/message/BaseMessage.java b/src/main/java/com/wildbit/java/postmark/client/data/model/message/BaseMessage.java index 89412d1..729c025 100644 --- a/src/main/java/com/wildbit/java/postmark/client/data/model/message/BaseMessage.java +++ b/src/main/java/com/wildbit/java/postmark/client/data/model/message/BaseMessage.java @@ -12,6 +12,7 @@ * Base email message object */ public class BaseMessage { + private String messageStream; private String from; private String to; private String cc; @@ -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; } diff --git a/src/main/java/com/wildbit/java/postmark/client/data/model/message/Message.java b/src/main/java/com/wildbit/java/postmark/client/data/model/message/Message.java index 3e4fbfd..941f7a3 100644 --- a/src/main/java/com/wildbit/java/postmark/client/data/model/message/Message.java +++ b/src/main/java/com/wildbit/java/postmark/client/data/model/message/Message.java @@ -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() { diff --git a/src/main/java/com/wildbit/java/postmark/client/data/model/templates/BaseTemplatedMessage.java b/src/main/java/com/wildbit/java/postmark/client/data/model/templates/BaseTemplatedMessage.java index 93f4d04..8d5ddff 100644 --- a/src/main/java/com/wildbit/java/postmark/client/data/model/templates/BaseTemplatedMessage.java +++ b/src/main/java/com/wildbit/java/postmark/client/data/model/templates/BaseTemplatedMessage.java @@ -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; @@ -39,6 +40,21 @@ 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; @@ -46,9 +62,25 @@ public BaseTemplatedMessage(String from, String to, Integer templateId) { 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; } @@ -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 * @@ -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 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: * diff --git a/src/main/java/com/wildbit/java/postmark/client/data/model/templates/TemplatedMessage.java b/src/main/java/com/wildbit/java/postmark/client/data/model/templates/TemplatedMessage.java index 5d78ced..29f1adc 100644 --- a/src/main/java/com/wildbit/java/postmark/client/data/model/templates/TemplatedMessage.java +++ b/src/main/java/com/wildbit/java/postmark/client/data/model/templates/TemplatedMessage.java @@ -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; }