· 9 years ago · Sep 12, 2016, 08:26 AM
1enter code here
2
3
4
5
6
7public static void main(String[] args) {
8 final String fromEmail = "info@creaciontpv.es"; //requires valid gmail id
9 final String password = "+++++++"; // correct password for gmail id
10 final String toEmail = "++++++@gmail.com"; // can be any email id
11
12 System.out.println("TLSEmail Start");
13 Properties props = new Properties();
14 props.put("mail.smtp.host", "smtp.1and1.es"); //SMTP Host
15 props.put("mail.smtp.port", "587"); //TLS Port
16 props.put("mail.smtp.auth", "true"); //enable authentication
17 props.put("mail.smtp.starttls.enable", "true"); //enable STARTTLS
18
19 //create Authenticator object to pass in Session.getInstance argument
20 Authenticator auth = new Authenticator() {
21 //override the getPasswordAuthentication method
22 protected PasswordAuthentication getPasswordAuthentication() {
23 return new PasswordAuthentication(fromEmail, password);
24 }
25 };
26 Session session = Session.getInstance(props, auth);
27
28 EmailUtil.sendEmail(session, toEmail,"TLSEmail Testing Subject", "TLSEmail Testing Body");
29
30 }
31
32
33
34
35
36
37
38enter code here
39
40enter code here