Failed to send out e-mail

I am trying to set up the email notification push in Jenkins. Getting error:

java.net.SocketException: Connection closed by remote host
	at sun.security.ssl.SSLSocketImpl.checkWrite(Unknown Source)
	at sun.security.ssl.AppOutputStream.write(Unknown Source)
	at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:116)
	at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
	at java.io.BufferedOutputStream.flush(Unknown Source)
	at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:2429)
Caused: javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
	java.net.SocketException: Connection closed by remote host

I have added “-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true” in jenkins.xml arguments section and restarted the jenkins.

Extended E-mail Notification Settings:
SMTP Server: smtp.office365.com
SMTP Port: 25 [tried with 587]
Use SSL: no
Use TSL: yes
Charset UTF-8

Same setting used under “E-mail Notification” settings as well

So can’t really help much on the jenkins side, thats just a generic “couldn’t make the connection” or more likely “other server closed the connection” error.

That being said, since you mentioned office365, I know they have a local binary you can run so you smtp to that localhost, then it submits to office365 via api. It apparently works a lot better.

How to set up a multifunction device or application to send email using Microsoft 365 or Office 365 | Microsoft Docs maybe? I don’t use office365 myself so I don’t know.

Unfortunately, troubleshooting of mail issues is difficult since logging is inadequate.

Can you create a custom log recorder with the following setting:

com.sun.mail.smtp.protocol at the FINEST level

https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html

After configuring the log recorder, please try sending mail and log recorded should post very detailed information.