From a91a923ff0a6ad98f5a0cbd8c7f4ebc0c8870f79 Mon Sep 17 00:00:00 2001 From: Steve Hu Date: Fri, 29 Dec 2017 17:04:30 -0500 Subject: [PATCH] fixes #147 Add email sender module and update secret.yml --- .../java/com/networknt/email/EmailConfig.java | 5 ++++ .../java/com/networknt/email/EmailSender.java | 24 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/email/src/main/java/com/networknt/email/EmailConfig.java b/email/src/main/java/com/networknt/email/EmailConfig.java index e8638151b6..76433f5695 100644 --- a/email/src/main/java/com/networknt/email/EmailConfig.java +++ b/email/src/main/java/com/networknt/email/EmailConfig.java @@ -1,5 +1,10 @@ package com.networknt.email; +/** + * Email Configuration + * + * @author Steve Hu + */ public class EmailConfig { String host; String port; diff --git a/email/src/main/java/com/networknt/email/EmailSender.java b/email/src/main/java/com/networknt/email/EmailSender.java index ed2dbf744d..871162cead 100644 --- a/email/src/main/java/com/networknt/email/EmailSender.java +++ b/email/src/main/java/com/networknt/email/EmailSender.java @@ -13,6 +13,11 @@ import javax.mail.internet.MimeMultipart; import java.util.Properties; +/** + * Email sender that support both text and attachment. + * + * @author Steve Hu + */ public class EmailSender { public static final String CONFIG_EMAIL = "email"; public static final String CONFIG_SECRET = "secret"; @@ -23,6 +28,14 @@ public class EmailSender { public EmailSender() { } + /** + * Send email with a string content. + * + * @param to destination email address + * @param subject email subject + * @param content email content + * @throws MessagingException message exception + */ public void sendMail (String to, String subject, String content) throws MessagingException{ Properties props = new Properties(); props.put("mail.smtp.user", emailConfg.getUser()); @@ -48,6 +61,15 @@ public void sendMail (String to, String subject, String content) throws Messagin Transport.send(message); } + /** + * Send email with a string content and attachment + * + * @param to destination eamil address + * @param subject email subject + * @param content email content + * @param filename attachment filename + * @throws MessagingException messaging exception + */ public void sendMailWithAttachment (String to, String subject, String content, String filename) throws MessagingException{ Properties props = new Properties(); props.put("mail.smtp.user", emailConfg.getUser()); @@ -70,7 +92,7 @@ public void sendMailWithAttachment (String to, String subject, String content, S BodyPart messageBodyPart = new MimeBodyPart(); // Now set the actual message - messageBodyPart.setText("This is message body"); + messageBodyPart.setText(content); // Create a multipar message Multipart multipart = new MimeMultipart();