Skip to end of metadata
Go to start of metadata

This page constitutes random notes from my work day as an Atlassian product consultant, put up in the vague hope they might benefit others. Expect rambling, reference to unsolved problems, and plenty of stacktraces. Check the date as any information given is likely to be stale.

Sending email via Postfix

I generally like to configure Jira and Confluence to send outgoing emails to localhost , and there have Postfix do the final mail delivery:

Delegating to Postfix has at least three benefits:

  • It keeps sensitive SMTP credentials out of Jira
  • I can configure Postfix on staging to 'blackhole' all outgoing emails (i.e. send them to a local file), so when production Jira data is run on staging, there's no chance of staging accidentally emailing people even if I forgot to set -Datlassian.mail.senddisabled=true 
  • It gets emails out of Jira's "useless" (to quote Jira's tech lead) mail queue as fast as possible, into a competently designed MTA that actually persists emails across restarts and handles retries to overcome transient errors.

Postfix's message size limit

One caveat I discovered today: Postfix will reject emails larger than a certain size (the message_size_limit parameter), including emails from Jira. If you have JETI installed, and users use JETI to email issues with their attachments, then it's quite easy for Jira to be sending JETI emails over 10Mb. Postfix rejects them, and they end up in the Jira error queue, where they languish forever until Jira is restarted, whereupon they are lost (did I mention "useless"?).

So if you don't want to lose your outgoing JETI emails, increase Postfix's message_size_limit  to whatever you're comfortable sending. In /etc/postfix/main.cf:

# Increase the maximum email size from 10Mb to 50Mb. https://www.redradishtech.com/x/JoAjAQ
message_size_limit = 50240000

Then sudo postfix reload

SMTP timeouts


Following increasing the message_size_limit , I noticed a SocketTimeoutExceptions in your atlassian-jira-outgoing-mail.log:

2019-12-17 22:11:08,828 ERROR [] Sending mailitem To='[email protected]' Subject='Issue Updated: (IT-183421) Sample ticket' From='null' FromName='Jeff Turner (Jira)' Cc='' Bcc='' ReplyTo='null' InReplyTo='<[email protected]>' MimeType='text/html' Encoding='UTF-8' Multipart='[email protected]' MessageId='[email protected]' ExcludeSubjectPrefix=false' [email protected] 1330x2600246x1 svwdbg 63.80.172.147 /secure/admin/MailQueueAdmin.jspa Error occurred in sending e-mail: To='[email protected]' Subject='Issue Updated: (IT-183421) Sample ticket' From='null' FromName='Jeff Turner (Jira)' Cc='' Bcc='' ReplyTo='null' InReplyTo='<[email protected]>' MimeType='text/html' Encoding='UTF-8' Multipart='[email protected]' MessageId='[email protected]' ExcludeSubjectPrefix=false'
com.atlassian.mail.MailException: javax.mail.MessagingException: Exception reading response;
      nested exception is:
        java.net.SocketTimeoutException: Read timed out
        at com.atlassian.mail.server.impl.SMTPMailServerImpl.sendWithMessageId(SMTPMailServerImpl.java:222) [atlassian-mail-5.0.0.jar:?]
        at com.atlassian.mail.queue.SingleMailQueueItem.send(SingleMailQueueItem.java:44) [atlassian-mail-5.0.0.jar:?]
...
Caused by: javax.mail.MessagingException: Exception reading response;
      nested exception is:
        java.net.SocketTimeoutException: Read timed out
        at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2445) [javax.mail-1.6.0.jar:1.6.0]
        at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2322) [javax.mail-1.6.0.jar:1.6.0]
        at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:2095) [javax.mail-1.6.0.jar:1.6.0]
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1301) [javax.mail-1.6.0.jar:1.6.0]
        at com.atlassian.mail.server.impl.SMTPMailServerImpl.sendMimeMessage(SMTPMailServerImpl.java:242) [atlassian-mail-5.0.0.jar:?]
        at com.atlassian.mail.server.managers.EventAwareSMTPMailServer.sendMimeMessage(EventAwareSMTPMailServer.java:25) [classes/:?]
        at com.atlassian.mail.server.impl.SMTPMailServerImpl.sendWithMessageId(SMTPMailServerImpl.java:184) [atlassian-mail-5.0.0.jar:?]
        ... 297 more
Caused by: java.net.SocketTimeoutException: Read timed out
        at java.base/java.net.SocketInputStream.socketRead0(Native Method) [?:?]
        at java.base/java.net.SocketInputStream.socketRead(SocketInputStream.java:115) [?:?]
        at java.base/java.net.SocketInputStream.read(SocketInputStream.java:168) [?:?]
        at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140) [?:?]
        at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:126) [javax.mail-1.6.0.jar:1.6.0]
        at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:252) [?:?]
        at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:271) [?:?]
        at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:104) [javax.mail-1.6.0.jar:1.6.0]
        at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2425) [javax.mail-1.6.0.jar:1.6.0]
        ... 303 more

The notification in the error queue was still there, but Postfix indicated that it had received and forwarded on the email!

Jira has a Timeout  setting for SMTP servers in the Outgoing Mail  section, and the default value is 10 seconds. From the stacktrace, it appears Jira opened a SMTP connection to Postgres, sent the large email (in my case, 23Mb), and then timed out waiting for a response from Postgres. Postgres considered the delivery a success, while Jira considered it a failure, and left the email in the error queue. Clicking 'Resend error queue' results in the same email being sent again.

The fix for this is to increase Jira's SMTP timeout, which can be done in the SMTP Mail Server settings under Outgoing Mail. On the principle of avoiding Jira's error queue at all costs, this timeout should be set to something large - anything less than 1 minute, which is the queue flush frequency:

  • No labels