comparison src/luan/modules/mail/MailSender.java @ 1765:1ffe1e06ea55

SSL for port 465
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 May 2023 10:29:55 -0600
parents 0c46edec25dd
children
comparison
equal deleted inserted replaced
1764:527c53b91a50 1765:1ffe1e06ea55
3 import java.io.IOException; 3 import java.io.IOException;
4 import java.net.Socket; 4 import java.net.Socket;
5 import java.util.Map; 5 import java.util.Map;
6 import java.util.LinkedHashMap; 6 import java.util.LinkedHashMap;
7 import java.util.List; 7 import java.util.List;
8 import javax.net.ssl.SSLSocket;
9 import goodjava.io.IoUtils;
8 import goodjava.mail.Message; 10 import goodjava.mail.Message;
9 import goodjava.mail.Smtp; 11 import goodjava.mail.Smtp;
10 import goodjava.mail.MailException; 12 import goodjava.mail.MailException;
11 import luan.Luan; 13 import luan.Luan;
12 import luan.LuanTable; 14 import luan.LuanTable;
103 throw new LuanException("body must be a string, binary, or list of part tables"); 105 throw new LuanException("body must be a string, binary, or list of part tables");
104 } 106 }
105 107
106 public void send(LuanTable mailTbl) throws LuanException, IOException, MailException { 108 public void send(LuanTable mailTbl) throws LuanException, IOException, MailException {
107 Message msg = message(mailTbl); 109 Message msg = message(mailTbl);
108 Socket socket = new Socket(host,port); 110 Socket socket;
111 if( port == 465 ) {
112 SSLSocket sslSocket = (SSLSocket)IoUtils.getSSLSocketFactory().createSocket(host,port);
113 sslSocket.startHandshake();
114 socket = sslSocket;
115 } else {
116 socket = new Socket(host,port);
117 }
109 Smtp smtp = new Smtp(socket); 118 Smtp smtp = new Smtp(socket);
110 if( username != null ) 119 if( username != null )
111 smtp.authenticate(username,password); 120 smtp.authenticate(username,password);
112 smtp.send(msg); 121 smtp.send(msg);
113 smtp.close(); 122 smtp.close();