aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/main/java/com/juick')
-rw-r--r--juick-api/src/main/java/com/juick/api/EmailManager.java16
1 files changed, 11 insertions, 5 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 a2ddbc3b..1573e7be 100644
--- a/juick-api/src/main/java/com/juick/api/EmailManager.java
+++ b/juick-api/src/main/java/com/juick/api/EmailManager.java
@@ -4,6 +4,7 @@ import com.juick.Message;
import com.juick.server.component.MessageEvent;
import com.juick.server.util.HttpBadRequestException;
import com.juick.service.EmailService;
+import com.juick.service.MessagesService;
import com.juick.service.SubscriptionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,21 +31,26 @@ public class EmailManager implements ApplicationListener<MessageEvent> {
EmailService emailService;
@Inject
SubscriptionService subscriptionService;
+ @Inject
+ MessagesService messagesService;
@Override
public void onApplicationEvent(MessageEvent event) {
Message msg = event.getMessage();
if (msg.getRid() == 0) {
+ String subject = String.format("New message from %s", msg.getUser().getName());
subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg.getMid())
.forEach(user -> emailService.getEmails(user.getUid(), true)
- .forEach(email -> emailNotify(email, msg)));
+ .forEach(email -> emailNotify(email, subject, msg)));
} else {
+ Message originalMessage = messagesService.getMessage(msg.getMid());
+ String subject = String.format("New reply to %s", originalMessage.getUser().getName());
subscriptionService.getUsersSubscribedToComments(msg.getMid(), msg.getUser().getUid())
.forEach(user -> emailService.getEmails(user.getUid(), true)
- .forEach(email -> emailNotify(email, msg)));
+ .forEach(email -> emailNotify(email, subject, msg)));
}
}
- void emailNotify(String email, Message msg) {
+ void emailNotify(String email, String subject, Message msg) {
Properties prop = System.getProperties();
prop.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(prop);
@@ -53,11 +59,11 @@ public class EmailManager implements ApplicationListener<MessageEvent> {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("juick@juick.com"));
message.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(email));
- message.setSubject(String.format("New message from %s", msg.getUser().getName()));
+ message.setSubject(subject);
message.setText(String.format("%s\n%s\n---\nYou are receiving this because you are subscribed to this user " +
"or discussion. Configure notifications at https://juick.com/settings",
formatPost(msg), formatUrl(msg)));
- transport.send(message);
+ transport.sendMessage(message, message.getAllRecipients());
} catch (MessagingException ex) {
logger.error("mail exception", ex);
}