I am trying to use my office365 SMTP server to send email notifications for failed pipelines with Jenkins using the Email Extension plugin. I'm getting a 501 5.5.4 Invalid domain name
when testing in debug mode with a failed pipeline. The junk characters don't seem right after the EHLO and HELO commands, but I don't see a way to configure the hostname. Anyone else run into this?
Successfully created MimeMessage
Sending email to: scoots@website.com
DEBUG: getProvider() returning jakarta.mail.Provider[TRANSPORT,smtp,org.eclipse.angus.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=smtp-mail.outlook.com, user=jenkins, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.office365.com", port 587, isSSL false
220 BN9PR03CA0850.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 29 Aug 2024 20:27:00 +0000 [08DCC75C8712D891]
DEBUG SMTP: connected to host "smtp.office365.com", port: 587
EHLO internalr8.internal���������������
501 5.5.4 Invalid domain name [BN9PR03CA0850.namprd03.prod.outlook.com 2024-08-29T20:27:06.007Z 08DCC75C8712D891]
HELO internalr8.internal���������������
501 5.5.4 Invalid domain name [BN9PR03CA0850.namprd03.prod.outlook.com 2024-08-29T20:27:11.007Z 08DCC75C8712D891]
MessagingException message: 501 5.5.4 Invalid domain name [BN9PR03CA0850.namprd03.prod.outlook.com 2024-08-29T20:27:11.007Z 08DCC75C8712D891]
My current theory is that something about the host it is picking up is causing a syntax error. I was able to send a test email from the command line with swak
, so the SMTP server is functioning and works with the server hostname. I have a different hostname for jenkins.
In /etc/hosts, there are multiple FQDNs for the same IP address (IT maintained):
XX.X.X.XX internalr8.internal internal-alias internal.internal
My Jenkins Location is https://internal.internal/
, and I have "JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true"
in my Jenkins configuration.
This was caused by hidden characters in the /etc/hosts file.
This was the output of cat /etc/hosts
XX.X.X.XX internalr8.internal internal-alias internal.internal
but this was the output of cat -v /etc/hosts to look for hidden characters:
XX.X.X.XX internalr8.internalM-BM- M-BM- M-BM- M-BM- M-BM- M-BM- M-BM- M-BM- M-BM- M-BM- M-BM- M-BM- M-BM- M-BM- M-BM- internal-alias internal.internal
This matches the number of unknown characters from the output of the EHLO/HELO commands (15). Hidden characters were probably added by someone's text editors, and most things work most of the time... but apparently not this plugin :)
Since removing them, the plugin works perfectly!