aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/notification/NotificationMail.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2018-06-26 09:22:22 +0500
committerAbyss777 <abyss@fox5.ru>2018-06-26 09:22:22 +0500
commitaba402226403f8b3eb58cc01e8f536eb4104d35a (patch)
treeec884994ad90365fa9b385465a80391606f6d970 /src/org/traccar/notification/NotificationMail.java
parentc700bfdb66071ba224ddf01e9827e721562fed7a (diff)
parent575deac9e2df1cbd0601328f7ea7a9f22029fa43 (diff)
downloadtrackermap-server-aba402226403f8b3eb58cc01e8f536eb4104d35a.tar.gz
trackermap-server-aba402226403f8b3eb58cc01e8f536eb4104d35a.tar.bz2
trackermap-server-aba402226403f8b3eb58cc01e8f536eb4104d35a.zip
Merge remote-tracking branch 'ivanfmartinez/notifications'
# Conflicts: # src/org/traccar/Context.java
Diffstat (limited to 'src/org/traccar/notification/NotificationMail.java')
-rw-r--r--src/org/traccar/notification/NotificationMail.java62
1 files changed, 26 insertions, 36 deletions
diff --git a/src/org/traccar/notification/NotificationMail.java b/src/org/traccar/notification/NotificationMail.java
index 6c81ecc79..fb89bf5bd 100644
--- a/src/org/traccar/notification/NotificationMail.java
+++ b/src/org/traccar/notification/NotificationMail.java
@@ -32,10 +32,7 @@ import org.traccar.model.Event;
import org.traccar.model.Position;
import org.traccar.model.User;
-public final class NotificationMail {
-
- private NotificationMail() {
- }
+public final class NotificationMail extends Notificator {
private static Properties getProperties(PropertiesProvider provider) {
Properties properties = new Properties();
@@ -84,7 +81,8 @@ public final class NotificationMail {
return properties;
}
- public static void sendMailSync(long userId, Event event, Position position) throws MessagingException {
+ @Override
+ public void sendSync(long userId, Event event, Position position) throws NotificationException {
User user = Context.getPermissionsManager().getUser(userId);
Properties properties = null;
@@ -103,40 +101,32 @@ public final class NotificationMail {
MimeMessage message = new MimeMessage(session);
- String from = properties.getProperty("mail.smtp.from");
- if (from != null) {
- message.setFrom(new InternetAddress(from));
- }
-
- message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
- MailMessage mailMessage = NotificationFormatter.formatMailMessage(userId, event, position);
- message.setSubject(mailMessage.getSubject());
- message.setSentDate(new Date());
- message.setContent(mailMessage.getBody(), "text/html; charset=utf-8");
-
- Transport transport = session.getTransport();
try {
- Context.getStatisticsManager().registerMail();
- transport.connect(
- properties.getProperty("mail.smtp.host"),
- properties.getProperty("mail.smtp.username"),
- properties.getProperty("mail.smtp.password"));
- transport.sendMessage(message, message.getAllRecipients());
- } finally {
- transport.close();
- }
- }
+ String from = properties.getProperty("mail.smtp.from");
+ if (from != null) {
+ message.setFrom(new InternetAddress(from));
+ }
- public static void sendMailAsync(final long userId, final Event event, final Position position) {
- new Thread(new Runnable() {
- public void run() {
- try {
- sendMailSync(userId, event, position);
- } catch (MessagingException error) {
- Log.warning(error);
- }
+ message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
+ MailMessage mailMessage = NotificationFormatter.formatFullMessage(userId, event, position);
+ message.setSubject(mailMessage.getSubject());
+ message.setSentDate(new Date());
+ message.setContent(mailMessage.getBody(), "text/html; charset=utf-8");
+
+ Transport transport = session.getTransport();
+ try {
+ Context.getStatisticsManager().registerMail();
+ transport.connect(
+ properties.getProperty("mail.smtp.host"),
+ properties.getProperty("mail.smtp.username"),
+ properties.getProperty("mail.smtp.password"));
+ transport.sendMessage(message, message.getAllRecipients());
+ } finally {
+ transport.close();
}
- }).start();
+ } catch (MessagingException e) {
+ throw new NotificationException(e);
+ }
}
}