Jenkins and Office365 email notification settings
Asked Answered
M

8

19

Environment:

  • Windows 2008 R2
  • Jenkins 1.580.2 LTS
  • Mailer plugin 1.12
  • Email Extension Plugin 2.39
  • Java 8

I have some problems with configuring my Jenkins CI server to send email notifications after moving to the Business account in Office365. So here is the my configurations:

  • Jenkins is started with StartTLS support (with parameter '-Dmail.smtp.starttls.enabled=true')
  • SMTP server is 'smtp.office365.com'
  • SMTP port is 587
  • SSL is disabled for SMTP authention
  • Account is real and password is correct
  • Account is specified like [email protected]

Looks like message should be sent correctly but the email message is NOT sent.

The following error occurs:

Failed to send out e-mail

com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2057)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1580)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1097)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at hudson.tasks.Mailer$DescriptorImpl.doSendTestMail(Mailer.java:527)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:298)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:161)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:96)
at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:121)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:745)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:875)
at org.kohsuke.stapler.MetaClass$6.doDispatch(MetaClass.java:249)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:745)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:875)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:648)
at org.kohsuke.stapler.Stapler.service(Stapler.java:237)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:686)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1494)
at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:96)
at hudson.plugins.greenballs.GreenBallFilter.doFilter(GreenBallFilter.java:58)
at hudson.util.PluginServletFilter$1.doFilter(PluginServletFilter.java:99)
at hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:88)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
at hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:48)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:84)
at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:51)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at jenkins.security.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:117)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at jenkins.security.BasicHeaderProcessor.doFilter(BasicHeaderProcessor.java:86)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
at hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:67)
at hudson.security.ChainedServletFilter$1.doFilter(ChainedServletFilter.java:87)
at hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76)
at hudson.security.HudsonFilter.doFilter(HudsonFilter.java:164)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:46)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1482)
at hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:81)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1474)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:499)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:533)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:960)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1021)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at winstone.BoundedExecutorService$1.run(BoundedExecutorService.java:77)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Could please someone help me with this? Thank you

Marked answered 15/1, 2015 at 14:57 Comment(0)
M
4

I used SMTP port 25 instead of 587 and it works

Marked answered 26/8, 2015 at 15:40 Comment(0)
T
31

After review the answers here I still got the error:

Client does not have permissions to send as this sender

So what I missed is to set the System Admin e-mail address and than everything worked well - probably the email plugin using the System Admin e-mail to connect the mailbox .

Here are all the steps to configure the mail notification (also email ext):

Go to manage jenkins > configure system:

under Jenkins Location

System Admin e-mail address: [email protected]

under Extended E-mail Notification:

SMTP server: smtp.office365.com 

Default user e-mail suffix: @domain.com

User Name: [email protected]

Password: ###########

Use SSL: no

SMTP Port: 25 or 587

Charset UTF-8

edit file: "/etc/default/jenkins"

sudo vim /etc/default/jenkins

add the line:

JAVA_ARGS="-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true"

restart jenkins

sudo /etc/init.d/jenkins restart

tested on ubuntu 16

Turne answered 28/3, 2017 at 10:45 Comment(4)
Thank you for pointing out the "System Administrator e-mail address" setting. I was trying to figure out how to make the "nobody@nowhere" address go away for an hour.Marcelo
JAVA_ARGS="-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true" solved my problem.Aves
System Admin e-mail address I am giving as Sometag<[email protected]> , I am not getting the tag in the email.instead I am getting the name configured in outlook. This happens only with outlook, if I configure with gmail it works fineReliquary
Since Jenkins 2.332.1 and 2.335 Systemd is used to manage services (jenkins.io/doc/book/system-administration/systemd-services). So to set the "-Dmail.stmp.starttls.enable=true" option, you need to now use "sudo systemctrl edit jenkins". Annoyingly /etc/default/jenkins still exists but changing it has no effect.Choker
T
11

TLS is not enabled.

Just add next java property for Jenkins on start:

-Dmail.smtp.starttls.enable=true

So for Ubuntu it can be configured here:

home/ubuntu# grep ^JAVA_ARGS /etc/default/jenkins
JAVA_ARGS="-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true"
Tranquilize answered 22/1, 2015 at 17:30 Comment(3)
Thank you for a comment, but you probably read a description not carefully. There is a point Jenkins is started with StartTLS support (with parameter '-Dmail.smtp.starttls.enabled=true') in description. So I'm sure that Jenkins was run with TLS enabled.Marked
Sorry to hear that did not work for you. I had exactly the same error, and for me, this was exactly what fixed it. Turned out the Ubuntu upgrade had wiped my custom -D argument from the defaults file. When in doubt, check Jenkins' /systemInfo page to see if the parameter was passed correctly.Loper
How to add this property and where? Means which file?Costrel
M
4

I used SMTP port 25 instead of 587 and it works

Marked answered 26/8, 2015 at 15:40 Comment(0)
B
3

If you are using AWS EC2 AMI Linux then this is a common problem. You need to edit /etc/sysconfig/jenkins and restart Jenkins.

You need to have both

JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true"

AND

JENKINS_ARGS="-Dmail.smtp.starttls.enable=true"

Bailsman answered 13/1, 2017 at 1:34 Comment(0)
E
1

According to my test, just the following parameters are required:

And if you don't want to touch/restart your jenkins at low level (-Dmail.smtp.starttls.enable=true) just add

mail.smtp.starttls.enable = true to the Advanced Email Properties

enter image description here

Elyssa answered 22/11, 2021 at 22:37 Comment(0)
C
1

Updated and tested for Ubuntu 22.04 LTS and Jenkins 2.426.3, based on the answer by dsaydon.

Despite editing /etc/default/jenkins and changing JAVA_ARGS as required...

JAVA_ARGS="-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true"

I was still getting the error...

com.sun.mail.smtp.SMTPSendFailedException: 451 5.7.3 STARTTLS is required to send mail 

This was because, even though the etc/default/jenkins config file existing and being updated, that config file hasn't been used by Jenkins since Jenkins 2.332.1 and Jenkins 2.335 (see https://www.jenkins.io/doc/book/system-administration/systemd-services/) and the version I had installed was newer.

Instead you have to use systemctl to edit the jenkins config.

I used the following command ...

sudo systemctl edit jenkins

And added the following at the top of the file between the comments shown ...

###Editing /etc/systemd/system/jenkins.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file

[Service]
Environment="JAVA_OPTS=-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true"

### Lines below this comment will be discarded

Then checked the changes were in effect with the command ...

systemctl cat jenkins

The end of the file should have this ...

# /etc/systemd/system/jenkins.service.d/override.conf
[Service]
Environment="JAVA_OPTS=-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true"

Then restarted jenkins using systemctl ...

sudo systemctl restart jenkins

This resolved the "STARTTLS is required" error for me.

Choker answered 16/2 at 10:23 Comment(0)
S
0

Steps:

  • Open debug of your mail sender
  • Check if you have got the following in your first debug info.

    DEBUG: setDebug: JavaMail version 1.3

  • Please upgrade your JavaMail version to one higher than 1.4 and it should be fixed without any code changes.

Sapphirine answered 25/8, 2015 at 4:52 Comment(0)
T
0

If you are using Jenkins in Kubernetes add below lines in your YAML file and make sure you have the same email in "System Admin e-mail address: "

containers:
     ...

      env:
        - name: JENKINS_OPTS
          value: "-Dmail.smtp.starttls.enable=true"

        - name: JENKINS_JAVA_OPTIONS
          value: "-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true"

        - name: JAVA_OPTS
          value: >-
            -Djava.awt.headless=true
            -Dmail.smtp.starttls.enable=true
Tobitobiah answered 11/2, 2020 at 19:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.