changeset 1829:0eb615de1f80

add mail helo
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 22 Sep 2024 20:05:54 -0600
parents 09e90d94b7b5
children d72a52232f79
files src/goodjava/mail/Examples.java src/goodjava/mail/Smtp.java src/luan/modules/mail/MailSender.java
diffstat 3 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
diff -r 09e90d94b7b5 -r 0eb615de1f80 src/goodjava/mail/Examples.java
--- a/src/goodjava/mail/Examples.java	Sun Sep 15 19:51:16 2024 -0600
+++ b/src/goodjava/mail/Examples.java	Sun Sep 22 20:05:54 2024 -0600
@@ -12,7 +12,7 @@
 
 	private static Smtp newSmtp() throws IOException, MailException {
 		Socket socket = new Socket("smtpcorp.com",2525);
-		Smtp smtp = new Smtp(socket);
+		Smtp smtp = new Smtp(socket,"GoodJava");
 		smtp.authenticate("luan","luanhost2");
 		return smtp;
 	}
diff -r 09e90d94b7b5 -r 0eb615de1f80 src/goodjava/mail/Smtp.java
--- a/src/goodjava/mail/Smtp.java	Sun Sep 15 19:51:16 2024 -0600
+++ b/src/goodjava/mail/Smtp.java	Sun Sep 22 20:05:54 2024 -0600
@@ -17,14 +17,14 @@
 	private final Writer writer;
 	public final String ehlo;
 
-	public Smtp(Socket socket) throws IOException, MailException {
+	public Smtp(Socket socket,String helo) throws IOException, MailException {
 		this.socket = socket;
 		this.reader = new InputStreamReader(socket.getInputStream());
 		this.writer = new OutputStreamWriter(socket.getOutputStream());
 		String s = read();
 		if( !s.startsWith("220") )
 			throw new MailException(s);
-		write( "EHLO whatever\r\n" );
+		write( "EHLO " + helo + "\r\n" );
 		ehlo = read();
 		if( !ehlo.startsWith("250") )
 			throw new MailException(ehlo);
diff -r 09e90d94b7b5 -r 0eb615de1f80 src/luan/modules/mail/MailSender.java
--- a/src/luan/modules/mail/MailSender.java	Sun Sep 15 19:51:16 2024 -0600
+++ b/src/luan/modules/mail/MailSender.java	Sun Sep 22 20:05:54 2024 -0600
@@ -20,6 +20,7 @@
 	private final int port;
 	private final String username;
 	private final String password;
+	private final String helo;
 
 	public MailSender(LuanTable paramsTbl) throws LuanException {
 		Map<Object,Object> params = paramsTbl.asMap();
@@ -46,6 +47,9 @@
 		if( this.username==null && this.password!=null )
 			throw new LuanException( "username required with password" );
 
+		String helo = getString(params,"helo");
+		this.helo = helo!=null ? helo : "Luan";
+
 		if( !params.isEmpty() )
 			throw new LuanException( "unrecognized parameters: "+params );
 	}
@@ -115,7 +119,7 @@
 		} else {
 			socket = new Socket(host,port);
 		}
-		Smtp smtp = new Smtp(socket);
+		Smtp smtp = new Smtp(socket,helo);
 		if( username != null )
 			smtp.authenticate(username,password);
 		smtp.send(msg);