changeset 1765:1ffe1e06ea55

SSL for port 465
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 May 2023 10:29:55 -0600
parents 527c53b91a50
children 8df0b80e715e
files .hgignore src/goodjava/mail/Smtp.java src/luan/modules/mail/MailSender.java
diffstat 3 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon May 22 20:43:52 2023 -0600
+++ b/.hgignore	Fri May 26 10:29:55 2023 -0600
@@ -17,3 +17,4 @@
 backup/logs/
 backup/backups/
 backup/backups.copy/
+mine/
--- a/src/goodjava/mail/Smtp.java	Mon May 22 20:43:52 2023 -0600
+++ b/src/goodjava/mail/Smtp.java	Fri May 26 10:29:55 2023 -0600
@@ -24,7 +24,7 @@
 		String s = read();
 		if( !s.startsWith("220") )
 			throw new MailException(s);
-		write( "EHLO\r\n" );
+		write( "EHLO whatever\r\n" );
 		ehlo = read();
 		if( !ehlo.startsWith("250") )
 			throw new MailException(ehlo);
--- a/src/luan/modules/mail/MailSender.java	Mon May 22 20:43:52 2023 -0600
+++ b/src/luan/modules/mail/MailSender.java	Fri May 26 10:29:55 2023 -0600
@@ -5,6 +5,8 @@
 import java.util.Map;
 import java.util.LinkedHashMap;
 import java.util.List;
+import javax.net.ssl.SSLSocket;
+import goodjava.io.IoUtils;
 import goodjava.mail.Message;
 import goodjava.mail.Smtp;
 import goodjava.mail.MailException;
@@ -105,7 +107,14 @@
 
 	public void send(LuanTable mailTbl) throws LuanException, IOException, MailException {
 		Message msg = message(mailTbl);
-		Socket socket = new Socket(host,port);
+		Socket socket;
+		if( port == 465 ) {
+			SSLSocket sslSocket = (SSLSocket)IoUtils.getSSLSocketFactory().createSocket(host,port);
+			sslSocket.startHandshake();
+			socket = sslSocket;
+		} else {
+			socket = new Socket(host,port);
+		}
 		Smtp smtp = new Smtp(socket);
 		if( username != null )
 			smtp.authenticate(username,password);