diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-10-12 03:33:20 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-10-12 03:33:20 +1300 |
commit | b13aad0f2764d7112363ce188abc03ea9cd37ddd (patch) | |
tree | b421f312c9956d0c3d66d5099001eb7f7b0e6a19 /test/org/traccar/notification/NotificiationMailTest.java | |
parent | 94b5679115b0aef3fe449b40f248dd83fde68ac5 (diff) | |
download | trackermap-server-b13aad0f2764d7112363ce188abc03ea9cd37ddd.tar.gz trackermap-server-b13aad0f2764d7112363ce188abc03ea9cd37ddd.tar.bz2 trackermap-server-b13aad0f2764d7112363ce188abc03ea9cd37ddd.zip |
Improvements to mail module
Diffstat (limited to 'test/org/traccar/notification/NotificiationMailTest.java')
-rw-r--r-- | test/org/traccar/notification/NotificiationMailTest.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/org/traccar/notification/NotificiationMailTest.java b/test/org/traccar/notification/NotificiationMailTest.java new file mode 100644 index 000000000..9405ff94f --- /dev/null +++ b/test/org/traccar/notification/NotificiationMailTest.java @@ -0,0 +1,60 @@ +package org.traccar.notification; + +import org.junit.Assert; +import org.junit.Test; +import org.traccar.location.CellInfo; + +import javax.mail.Message; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import java.util.Properties; + +public class NotificiationMailTest { + + private static final String FROM = "notification@traccar.org"; + private static final String TO = "anton.tananaev@gmail.com"; + + private static final String BODY = "Test email body."; + private static final String SUBJECT = "Test"; + + private static final String SMTP_USERNAME = "username"; + private static final String SMTP_PASSWORD = "password"; + + private static final String HOST = "email-smtp.us-west-2.amazonaws.com"; + + private static final int PORT = 25; + + @Test + public void test() throws Exception { + + Properties props = System.getProperties(); + props.put("mail.transport.protocol", "smtps"); + props.put("mail.smtp.port", PORT); + + props.put("mail.smtp.auth", "true"); + props.put("mail.smtp.starttls.enable", "true"); + props.put("mail.smtp.starttls.required", "true"); + + Session session = Session.getInstance(props); + + MimeMessage msg = new MimeMessage(session); + msg.setFrom(new InternetAddress(FROM)); + msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO)); + msg.setSubject(SUBJECT); + msg.setContent(BODY,"text/plain"); + + Transport transport = session.getTransport(); + + try + { + transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD); + transport.sendMessage(msg, msg.getAllRecipients()); + } finally { + transport.close(); + } + + } + +} |