aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api/EmailManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/EmailManager.java')
-rw-r--r--juick-api/src/main/java/com/juick/api/EmailManager.java21
1 files changed, 18 insertions, 3 deletions
diff --git a/juick-api/src/main/java/com/juick/api/EmailManager.java b/juick-api/src/main/java/com/juick/api/EmailManager.java
index a01eac78..2f4065d0 100644
--- a/juick-api/src/main/java/com/juick/api/EmailManager.java
+++ b/juick-api/src/main/java/com/juick/api/EmailManager.java
@@ -14,10 +14,13 @@ import org.springframework.stereotype.Component;
import javax.inject.Inject;
import javax.mail.MessagingException;
+import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
import java.util.Properties;
import static com.juick.formatters.PlainTextFormatter.formatPost;
@@ -74,10 +77,22 @@ public class EmailManager implements ApplicationListener<MessageEvent> {
message.setFrom(new InternetAddress("juick@juick.com"));
message.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(email));
message.setSubject(subject);
- message.setText(String.format("%s\n%s\n\n---\nYou are receiving this because you are subscribed to this user " +
- "or discussion. Configure notifications at https://juick.com/settings?hash=%s",
+ String plainText = String.format("%s\n\n--\nYou are receiving this because you are subscribed to this user " +
+ ", discussion or tag. Reply to this email directly or view it on Juick: %s.",
+ StringUtils.isNotEmpty(msg.getText()) ? formatPost(msg) : "", formatUrl(msg));
+ MimeBodyPart textBodyPart = new MimeBodyPart();
+ textBodyPart.setContent(plainText, "text/plain");
+ String htmlText = String.format("%s<br /><br />--<br />You are receiving this because you are subscribed to this user " +
+ ", discussion or tag. Reply to this email directly or <a href=\"%s\">view it</a> on Juick." +
+ "<br /><a href=\"https://juick.com/settings?hash=%s\">Configure or disable notifications</a>",
StringUtils.isNotEmpty(msg.getText()) ? formatPost(msg) : "", formatUrl(msg),
- userService.getHashByUID(userService.getUserByEmail(email).getUid())));
+ userService.getHashByUID(userService.getUserByEmail(email).getUid()));
+ MimeBodyPart htmlBodyPart = new MimeBodyPart();
+ htmlBodyPart.setContent(htmlText, "text/html");
+ Multipart multipart = new MimeMultipart("alternative");
+ multipart.addBodyPart(textBodyPart);
+ multipart.addBodyPart(htmlBodyPart);
+ message.setContent(multipart);
message.setHeader("List-Unsubscribe", String.format("https://juick.com/settings?hash=%s", userService.getHashByUID(userService.getUserByEmail(email).getUid())));
message.saveChanges();
transport.connect();