blob: ffdd62a5b431565f92ae57b8da6445a711f741f9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package com.mavlushechka.notary.util;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
public class EmailSender {
private final static Session SESSION;
static {
Properties properties = new Properties();
properties.put("mail.smtp.auth", true);
properties.put("mail.smtp.starttls.enable", true);
properties.put("mail.smtp.host", "smtp.mailtrap.io");
properties.put("mail.smtp.port", "2525");
properties.put("mail.smtp.ssl.trust", "smtp.mailtrap.io");
properties.put("mail.smtp.ssl.protocols", "TLSv1.2");
SESSION = Session.getInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("4df6840637b3c8", "829aff4fc98967");
}
});
}
public static void send(String from, String to, String subject, String messageText) throws MessagingException {
Message message = new MimeMessage(SESSION);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
message.setSubject(subject);
MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setContent(messageText, "text/html; charset=utf-8");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mimeBodyPart);
message.setContent(multipart);
Transport.send(message);
}
}
|