diff options
author | Vitaly Takmazov | 2019-08-21 11:09:54 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-08-21 11:09:54 +0300 |
commit | b10719e4c69b489830001c9707f6e2eba265abad (patch) | |
tree | 29c14701fb43a3380cb71a07f48efa86eccfe0e9 /src/main/java/com/juick/server/EmailManager.java | |
parent | d9d481d824f920f797cff4d9ca92c8cd9b895389 (diff) |
Settings API
Diffstat (limited to 'src/main/java/com/juick/server/EmailManager.java')
-rw-r--r-- | src/main/java/com/juick/server/EmailManager.java | 9 |
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; } } |