Email notifications from Confluence are duplicated using Microsoft Exchange Server

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Problem

Duplicate emails are sent to people using remote Exchange servers; or mail stops being sent and are added to the Mail Queue. 

The following error might appear in the atlassian-confluence.log:

ERROR [NotificationSender:thread-2] [plugin.notifications.dispatcher.NotificationErrorRegistryImpl] addError Error sending notification to server '<Unknown>'(-1) for INDIVIDUAL task (resent 4 times): Error sending to individual '8a818228609ba3ef01509ecd16fb0669' on server 'System Mail'
NotificationException: javax.mail.MessagingException: Exception reading response;
  nested exception is:
	java.net.SocketTimeoutException: Read timed out
......

Cause

Mail stops sending because the mail thread cannot connect to the server, and there is no timeout set.

Workarounds

Increase the SMTP Timeout

Increasing the SMTP Timeout will prevent Confluence from timing out too quickly and duplicating the messages. From How To Set the SMTP Timeout in Confluence:

Click here to expand...

Solution

  1. Stop Confluence

  2. Back up your Confluence database

  3. Run the following query on the database: 

    SELECT * FROM BANDANA WHERE BANDANAKEY = 'atlassian.confluence.smtp.mail.accounts';
  4. Find the following in the BANDANAVALUE:

    <property name="mail.smtp.timeout" value="10000"/>

    and

    <property name="mail.smtp.connectiontimeout" value="10000"/>
  5. Use SQL's REPLACE function to increase the values
    EXAMPLE:

    UPDATE BANDANA
       SET BANDANAVALUE = replace(BANDANAVALUE,'<property name="mail.smtp.connectiontimeout" value="10000"/>','<property name="mail.smtp.connectiontimeout" value="20000"/>')
     WHERE BANDANAVALUE LIKE '%mail.smtp.connectiontimeout%';
    
    
    UPDATE BANDANA
       SET BANDANAVALUE = replace(BANDANAVALUE,'<property name="mail.smtp.timeout" value="10000"/>','<property name="mail.smtp.timeout" value="20000"/>')
     WHERE BANDANAVALUE LIKE '%mail.smtp.timeout%';


    For MS SQL the update statements are:

    UPDATE BANDANA
       SET BANDANAVALUE = CAST(REPLACE(CAST(BANDANAVALUE as nvarchar(max)),'<property name="mail.smtp.timeout" value="10000"/>','<property name="mail.smtp.timeout" value="20000"/>') as ntext) 
     WHERE BANDANAVALUE LIKE '%mail.smtp.connectiontimeout%';
    
    UPDATE BANDANA
       SET BANDANAVALUE = CAST(REPLACE(CAST(BANDANAVALUE as nvarchar(max)),'<property name="mail.smtp.connectiontimeout" value="10000"/>','<property name="mail.smtp.connectiontimeout" value="20000"/>') as ntext) 
     WHERE BANDANAVALUE LIKE '%mail.smtp.timeout%';
    

    Also note:  If email settings are updated, the settings will revert to the default.  You will need to reproduce these steps after the change has been made.

  6. Restart Confluence

Switch to a JNDI Connector 

If a JNDI Connector is configured in Tomcat, there is no timeout value set and it defaults to -1 which is unlimited. This will prevent Confluence from timing out too quickly and duplicating the messages. From Connect Exchange Server To Confluence via JNDI:

Click here to expand...

  1. Stop Confluence.
  2. Move (don't copy) the following files from <confluence-install>\confluence\WEB-INF\lib to <confluence-install>\lib:

    com.sun.activation_jakarta.activation-x.x.x.jar
    com.sun.mail_jakarta.mail-x.x.x.jar

    (x.x.x. represents the version numbers on the jar files in your installation)

    Don't 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. Edit the <confluence-install>\conf\server.xml file and add the following at the end of the Confluence <context> tag, just before </Context>.
    Note: you're editing the <context> tag that contains the Confluence context path, not the one that contains the Synchrony context path.

    <Resource name="mail/GmailSMTPServer"
        auth="Container"
        type="javax.mail.Session"
        mail.smtp.host="smtp.gmail.com"
        mail.smtp.port="465"
        mail.smtp.auth="true"
        mail.smtp.user="yourEmailAddress@gmail.com"
        password="yourPassword"
        mail.smtp.starttls.enable="true"
        mail.transport.protocol="smtps"
        mail.smtp.socketFactory.class="javax.net.ssl.SSLSocketFactory"
    />
    
  4. Restart Confluence.
  5. Go to Administration  > General Configuration > Mail Servers.

  6. Select either Edit an existing configuration, or Add a new SMTP mail server.
  7. Edit the server settings as necessary, and set the JNDI Location as:

     java:comp/env/mail/GmailSMTPServer
    


    Note that the JNDI Location is case sensitive and must match the resource name specified in server.xml.

  8. Save your changes and send a test email.

Last modified on Mar 9, 2021

Was this helpful?

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