Skip to content

Commit

Permalink
fixes #147 Add email sender module and update secret.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu committed Dec 29, 2017
1 parent b0b6414 commit a91a923
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions email/src/main/java/com/networknt/email/EmailConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.networknt.email;

/**
* Email Configuration
*
* @author Steve Hu
*/
public class EmailConfig {
String host;
String port;
Expand Down
24 changes: 23 additions & 1 deletion email/src/main/java/com/networknt/email/EmailSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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();
Expand Down

0 comments on commit a91a923

Please sign in to comment.