Confluence unable to send email through Gmail server due to 'Read timed out'

Still need help?

The Atlassian Community is here for you.

Ask the community

Problem

Confluence fails to send email.

The following appears in the atlassian-confluence.log

com.atlassian.mail.MailException: javax.mail.MessagingException: Exception reading response;
  nested exception is:
	java.net.SocketTimeoutException: Read timed out

Cause

Confluence is configured to use a port other than 587 to connect to the Gmail server

Resolution

Confluence 5.6 and above

For Confluence 5.6 and above, you can set up Gmail through the admin console

  1. Go to Admin > Mail Servers
  2. Click 'Add a new SMTP mail server'
  3. Fill out your mail account details. 
  4. Enter smtp.gmail.com for the mail server and 587 for the port, and ensure you tick Use TLS:

Confluence 5.5.x and below

For Confluence 5.5.x and below, you will need to create a JNDI mail session and then have Confluence use it, as described below.

To do this for the Confluence distribution, please see Setting Up a Mail Session for the Confluence Distribution.

  1. Stop Confluence.
  2. Move (don't copy) activation-1.0.2.jar (if it exists) and mail-1.4.1.jar from /confluence/WEB-INF/lib to <Confluence Standalone install>/lib. Or if you are using Confluence WAR release, move to <Tomcat 5 install>/common/lib or <Tomcat 6 install>/lib.

    The exact version numbers on these jar files may vary, but that should not matter. As of Confluence 5.2.3, activation-1.0.2.jar no longer exists, and does not need to be moved or downloaded

    Do not leave a renamed backup of the jar files in /confluence/WEB-INF/lib. Even with a different file name, the files will still be loaded as long as it remains in the directory.

  3. Add the following Resource tag in confluence.xml or server.xml located at <confluence-install>/conf, inside the <Context> node (substituting username and password), so it looks like this:

    Server.xml
    // The context tag here is for illustrative purposes only, to highlight where the Resource tag should be entered. You do not need to copy the Context tag, it will already exist in your file.
    <Context path="/confluence" docBase="../confluence" debug="0" reloadable="false" useHttpOnly="true">
        <!-- Logger is deprecated in Tomcat 5.5. Logging configuration for Confluence is specified in confluence/WEB-INF/classes/log4j.properties -->
        <Manager pathname="" />
     
    	// Copy this Resource tag into the Context tag in your server.xml, and enter your user and password details
        <Resource name="mail/Session"
            auth="Container"
            type="javax.mail.Session"
            mail.smtp.host="smtp.gmail.com"
            mail.smtp.port="465"
            mail.smtp.auth="true"
            mail.smtp.user="nobody@gmail.com"
            password="foobar"
            mail.smtp.starttls.enable="true"
            mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
        />
    	// End section to copy
    </Context>
  4. Restart your Confluence instance.
  5. Add java:comp/env/mail/Session to your JNDI mail configuration from Administration > Mail Servers.

Notes:

  • You may optionally add mail.debug="true" into the <Resource> to see logs generated by JavaMail.
  • If your Google account uses 2-step verification you will need to use an application password instead of your password.
  • Also, if you find connection errors using the port 465 please change it to 587.

 

Last modified on Mar 30, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.