Skip to content

SMTP STARTTLS #713

Closed
Closed

Description

@gitblit

Originally reported on Google Code with ID 417

Hi,

I'm wondering if it is possible to use a STARTTLS-enabled SMTP server for email notifications.
We're planning to deploy the ticket service so it's getting increasingly important
to have email notifications for things like new tickets, new comments or new commits
in tickets.

Now I'm trying to use the SMTP server of Office 365 which requires the client to use
STARTTLS (like GMail), and I couldn't get it to work. With smtps enabled, it says:

javax.mail.MessagingException: Could not connect to SMTP host: pod51013.outlook.com,
port: 587;
nested exception is: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext
connection?

Without smtps it says:

javax.mail.AuthenticationFailedException: No authentication mechansims supported by
both server and client

Am I missing something or is it currently an unsupported scenario? Thanks in advance,

Viktor

Reported by sundayfunday1234@outlook.com on 2014-04-30 11:35:56

Activity

  1. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Smtps works with Gmail - it uses 465 which may start off as SSL rather than starting
    plaintext.  Can you use 465?
    

    Reported by James.Moger on 2014-04-30 11:54:14

  2. self-assigned this
    on Aug 12, 2015
  3. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Unfortunately Office 365 doesn't support port 465. Details:
    
    http://office.microsoft.com/en-us/outlook-help/settings-for-pop-and-imap-access-for-office-365-for-business-or-microsoft-exchange-accounts-HA102908389.aspx
    
    

    Reported by sundayfunday1234@outlook.com on 2014-04-30 13:06:11

  4. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    I updated the javax.mail dependency to the current release. It may have fixes for starttls
    - or it may not.  This change has been pushed to develop, if you care to try it.
    

    Reported by James.Moger on 2014-05-05 15:23:14

  5. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Sure, thanks, but do I need to compile it from source?
    

    Reported by sundayfunday1234@outlook.com on 2014-05-06 10:23:50

  6. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Correct.  You'll need JDK7 and Ant.  Do you have those?
    

    Reported by James.Moger on 2014-05-06 11:32:49

  7. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Sure. I'm reading the build docs ATM:
    
    https://github.com/gitblit/gitblit/blob/develop/README.markdown#building-gitblit
    
    So can it work without Eclipse, too?
    

    Reported by sundayfunday1234@outlook.com on 2014-05-06 11:40:56

  8. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Yup.  That's how I build.
    

    Reported by James.Moger on 2014-05-06 11:46:34

  9. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    When I import the project into Eclipse the Build (All) options are greyed out.
    
    Also, when I try to run Ant from the command line with
    
    ant build.xml
    
    it downloads the moxie toolkit, then it says
    
    BUILD FAILED
    Target "build.xml" does not exist in the project "gitblit".
    

    Reported by sundayfunday1234@outlook.com on 2014-05-08 11:09:28

  10. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Just type "ant"
    

    Reported by James.Moger on 2014-05-08 12:16:15

  11. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    But you'll want to make sure you are on the "develop" branch.
    

    Reported by James.Moger on 2014-05-08 12:17:33

  12. 5 remaining items

  13. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Here's the output of gb config (btw I guess it'd be a good idea to automatically obfuscate
    at least mail.password, realm.ldap.password and server.storePassword):
    
    *git.acceptedPushTransports            : HTTP
    *git.allowAnonymousPushes              : true
    *git.allowCreateOnPush                 : false
    *git.onlyAccessBareRepositories        : true
    *git.packedGitLimit                    : 512m
    *git.sshBindInterface                  : localhost
    *git.streamFileThreshold               : 512m
    *groovy.customFields                   : "redmineProject=Identifier of the Redmine
    project to which this repo is added"
    *mail.adminAddresses                   : admin@foobar.net
    *mail.debug                            : true
    *mail.fromAddress                      : noreply@foobar.net
    *mail.password                         : ***
    *mail.port                             : 587
    *mail.server                           : smtp.office365.com
    *mail.username                         : noreply@foobar.net
    *realm.authenticationProviders         : ldap
    *realm.ldap.accountBase                : OU=Users,OU=Foobar,DC=ad,DC=foobar,DC=net
    *realm.ldap.admins                     : "@Git Admins"
    *realm.ldap.email                      : mail
    *realm.ldap.groupBase                  : OU=LDAP,OU=Groups,OU=Foobar,DC=ad,DC=foobar,DC=net
    *realm.ldap.maintainTeams              : true
    *realm.ldap.password                   : ***
    *realm.ldap.server                     : ldap://dc1.ad.foobar.net
    *realm.ldap.syncPeriod                 : 120 MINUTES
    *realm.ldap.uid                        : sAMAccountName
    *realm.ldap.username                   : ldap
    *realm.minPasswordLength               : 7
    *realm.redmine.url                     : http://example.com/redmine FIXME
    *server.certificateAlias               : scm.ad.foobar.net
    *server.httpPort                       : 80
    *server.httpsPort                      : 0
    *server.storePassword                  : ***
    *tickets.closeOnPushCommitMessageRegex : (?:gfixes|gcloses)[\s-]+#?(\d+)
    *tickets.service                       : com.gitblit.tickets.FileTicketService
    *web.allowFlashCopyToClipboard         : false
    *web.authenticateViewPages             : true
    *web.canonicalUrl                      : http://scm.ad.foobar.net
    *web.datestampLongFormat               : yyyy MMMM d (EEEE)
    *web.datetimestampLongFormat           : yyyy MMMM d (EEEE), HH:mm Z
    *web.headerLogo                        : ${baseFolder}/foobar.png
    *web.imageExtensions                   : bmp jpg jpeg gif png ico
    *web.loginMessage                      : /opt/gitblit-config/md/welcome.md
    *web.repositoriesMessage               : /opt/gitblit-config/md/repo.md
    *web.rootLink                          : /
    *web.showSearchTypeSelection           : true
    *web.siteName                          : Foobar Git
    *web.summaryShowReadme                 : true
    
    

    Reported by sundayfunday1234@outlook.com on 2014-05-08 16:39:02

  14. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Here's an example Tomcat mail.properties which we're using on several sites:
    
    
    mail.transport.protocol=smtp
    mail.smtp.host=podXXXXX.outlook.com (this is an alternative to smtp.office365.com and
    yes, i've tried this with gitblit, too)
    mail.smtp.port=587
    mail.smtp.starttls.enable=true
    mail.smtp.user=noreply@foobar.net
    mail.smtp.connectiontimeout=60000
    mail.smtp.timeout=60000
    mail.smtp.auth=true
    #mail.smtp.ehlo=true
    mail.debug=false
    x-default-recipient-email=john.smith@foobar.net
    x-sender-email=support@blah.com (this is a different user that noreply's been granted
    to send on behalf)
    x-sender-password=***
    x-sender-name=Blah Support
    

    Reported by sundayfunday1234@outlook.com on 2014-05-08 16:43:57

  15. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Gitblit does not set:
    
    mail.transport.protocol=smtp
    mail.smtp.user=noreply@foobar.net
    mail.smtp.connectiontimeout=60000
    mail.smtp.timeout=60000
    
    I think you are going to have to run this in the debugger to see why it's failing with
    your smtp config and where an adjustment needs to be made.  There is a unit test for
    debugging the MailService.
    
    1. Copy your gitblit.properties file to the root of your gitblit worktree and name
    it "mailtest.properties".
    2. Make sure you set mail.adminAddresses OR modify the test to hardcode an address.
    3. In Eclipse, navigate to src/tests/java/com/gitblit/tests/MailTest.java
    4. Right-click in the editor and Run As->JUnit test.
    

    Reported by James.Moger on 2014-05-08 17:02:26

  16. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Here's the console:
    
    
    2014-05-08 19:07:34 [INFO ] send: Test
    2014-05-08 19:07:39 [ERROR] Failed to send message
    com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.1 Client was not authenticated
    
        at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1829)
        at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1368)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:886)
        at javax.mail.Transport.send0(Transport.java:191)
        at javax.mail.Transport.send(Transport.java:120)
        at com.gitblit.service.MailService.run(MailService.java:273)
        at com.gitblit.tests.MailTest.testSendMail(MailTest.java:39)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    

    Reported by sundayfunday1234@outlook.com on 2014-05-08 17:09:46

  17. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Also, on the left there's a "Failure Trace". Here's that:
    
    
    java.lang.AssertionError: mail queue is not empty!
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.assertTrue(Assert.java:41)
        at com.gitblit.tests.MailTest.testSendMail(MailTest.java:41)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    
    
    There are also 5 errors under the "Problems" tab (all of them being "Invalid character
    constant" in various java files).
    

    Reported by sundayfunday1234@outlook.com on 2014-05-08 17:12:31

  18. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    The encoding problem is due to Eclipse's idiotic defaults on Windows.
    
    1. Right-click on the gitblit project and choose Properties (last menu item).
    2. First item (Resource): Set "Text file encoding" to UTF-8 and you might as well set
    the line delimeter to Unix.
    
    Once you do that the encoding failures should not re-occur.  The authentication failure
    is something you are going to have to dig into by setting breakpoints in MailService.run().
     I can't debug this for you through email or GoogleCode.  If you are not comfortable
    with that, then I don't know what to tell you.  Create a GMail account?
    

    Reported by James.Moger on 2014-05-08 17:20:25

  19. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    James, thanks for all the guidance. The good news is that I could finally get it to
    work, easier than I hoped. All it takes is just this:
    
    props.setProperty("mail.smtp.starttls.enable", "true");
    
    So now we could create a new check similar to isGmail, like isOffice365 with some URL
    matching and set this property there, but I wouldn't like it particularly because of
    the SMTP server aliases on Office 365. Not to mention that AFAIK all self-hosted, on-premises
    Exchange servers require STARTTLS *without* SMTPS, too.
    
    So I propose to go the more robust/flexible way and create a new option in gitblit.properties
    like mail.starttls.
    
    final boolean starttls = settings.getBoolean(Keys.mail.starttls, false);
    props.setProperty("mail.smtp.starttls.enable", String.valueOf(starttls));
    
    What do you think?
    

    Reported by sundayfunday1234@outlook.com on 2014-05-08 18:01:16

  20. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    Yes. Let's do that.  Would you to open a pull request?  Or do you want me to take care
    of it?
    

    Reported by James.Moger on 2014-05-08 18:51:50

  21. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    I opened a pullreq, I hope it's good enough:
    
    https://github.com/gitblit/gitblit/pull/183
    
    Thanks.
    

    Reported by sundayfunday1234@outlook.com on 2014-05-08 19:19:45

  22. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor

    Reported by James.Moger on 2014-05-08 19:28:39

    • Status changed: Queued
    • Labels added: Milestone-1.6.0
  23. gitblit commented on Aug 12, 2015

    @gitblit
    CollaboratorAuthor
    1.6.0 released.
    

    Reported by James.Moger on 2014-06-17 00:24:34

    • Status changed: Done
  24. eduardomb08 commented on May 3, 2016

    @eduardomb08

    Could you please add the encoding solution mentioned above in the build section from the main page?

    Below you find the referred solution instructions:

    1. Right-click on the gitblit project and choose Properties (last menu item).
    2. First item (Resource): Set "Text file encoding" to UTF-8 and you might as well set
      the line delimeter to Unix.

    Thanks in advance.

    Regards,

    Eduardo Monteiro de Barros

  25. modified the milestone: 1.6.0 on Dec 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions