diff --git a/pom.xml b/pom.xml index 25327e7..e9b39aa 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.nschwalbe postoffice - 0.1.1 + 0.1.2 org.springframework.boot diff --git a/src/main/java/de/nschwalbe/postoffice/PostOffice.java b/src/main/java/de/nschwalbe/postoffice/PostOffice.java index e31b6d1..14c320c 100644 --- a/src/main/java/de/nschwalbe/postoffice/PostOffice.java +++ b/src/main/java/de/nschwalbe/postoffice/PostOffice.java @@ -2,6 +2,7 @@ import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -33,6 +34,38 @@ public PostOffice(MailStorage mailStorage, JavaMailSender mailSender) { this.mailSender = mailSender; } + /** + * Creates a mail, stores it and sends it out later. This method returns immediately and does not wait for the mail server. + * + * @param subject the mail subject. + * @param from the sender address. + * @param to the recipient. + * @param content the mail body. + * @param isHtml true if mail body is html, if it is plain text set to false. + * @return the persisted mail + * @throws MessagingException if message creation failed due to some error. + */ + public PersistedMail postMail(String subject, MailAddress from, MailAddress to, String content, boolean isHtml) throws MessagingException { + MimeMessage mimeMessage = createMimeMessage(subject, from, Collections.singletonList(to), content, isHtml); + return postMail(mimeMessage); + } + + /** + * Creates a mail, stores it and sends it out later. This method returns immediately and does not wait for the mail server. + * + * @param subject the mail subject. + * @param from the sender address. + * @param to the recipient. + * @param html the mail body html part. + * @param text the mail body text part. + * @return the persisted mail. + * @throws MessagingException if message creation failed due to some error. + */ + public PersistedMail postMail(String subject, MailAddress from, MailAddress to, String html, String text) throws MessagingException { + MimeMessage mimeMessage = createMimeMessage(subject, from, Collections.singletonList(to), html, text); + return postMail(mimeMessage); + } + /** * Creates a mail, stores it and sends it out later. This method returns immediately and does not wait for the mail server. *