aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/EmailManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/server/EmailManager.java')
-rw-r--r--src/main/java/com/juick/server/EmailManager.java9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/main/java/com/juick/server/EmailManager.java b/src/main/java/com/juick/server/EmailManager.java
index 3d17a041..bd77d8d6 100644
--- a/src/main/java/com/juick/server/EmailManager.java
+++ b/src/main/java/com/juick/server/EmailManager.java
@@ -119,9 +119,9 @@ public class EmailManager implements NotificationListener {
String plainText = renderPlaintext(formatPost(msg), formatUrl(msg)).orElseThrow(IllegalStateException::new);
String hash = userService.getHashByUID(userService.getUserByEmail(email).getUid());
String htmlText = renderHtml(MessageUtils.formatHtml(msg), formatUrl(msg), msg, hash).orElseThrow(IllegalStateException::new);
- sendEmail(email, subject, plainText, htmlText, headers);
+ sendEmail(StringUtils.EMPTY, email, subject, plainText, htmlText, headers);
}
- public void sendEmail(String to, String subject, String textPart, String htmlPart, Map<String, String> messageHeaders) {
+ public boolean sendEmail(String from, String to, String subject, String textPart, String htmlPart, Map<String, String> messageHeaders) {
Properties prop = System.getProperties();
prop.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(prop);
@@ -134,7 +134,8 @@ public class EmailManager implements NotificationListener {
}
}
};
- message.setFrom(new InternetAddress("juick@juick.com"));
+ String fromAddress = StringUtils.isNotEmpty(from) ? from : "juick@juick.com";
+ message.setFrom(fromAddress);
message.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
MimeBodyPart textBodyPart = new MimeBodyPart();
@@ -161,8 +162,10 @@ public class EmailManager implements NotificationListener {
message.saveChanges();
transport.connect();
transport.sendMessage(message, message.getAllRecipients());
+ return true;
} catch (MessagingException ex) {
logger.error("mail exception", ex);
+ return false;
}
}