Clarity PPM: GEL emails using addRecipient Java method failing to deliver emails when there are multiple recipients in To and CC
search cancel

Clarity PPM: GEL emails using addRecipient Java method failing to deliver emails when there are multiple recipients in To and CC

book

Article ID: 222834

calendar_today

Updated On:

Products

Clarity PPM SaaS

Issue/Introduction

GEL script emails that have multiple recipients in the To: and CC: are not being delivered and are returned with the following error message:

A message was received from this address by our systems that had errors in the SMTPAPI header, and cannot be processed due to the following:
 - 4 duplicate cc header detected, rfc5322 states that there should be a max of 1
If you require assistance in working with the SendGrid API, please contact us at [email protected]

Note: The error messages will not be in the Clarity logs because it has bounced at the email server layer. The SENDER address in the gel script will receive the failure notice. as an attachment. 


GEL scripts can use custom Java classes to send email notifications. 
In this case, javax.mail.internet.InternetAddress and the method used within this class is addRecipient
When the addRecipient method is used, the To: and CC: headers get duplicated in the emails being sent out. 
For example, if there are 3 recipients in the To, the email header will be:

To:[email protected]
To:[email protected]
To:[email protected]

However, if  <gel:email> or <email:email> is used the header would look like:

To: [email protected];[email protected];[email protected]

Cause

On 10th Aug, the SaaS email vendor has pushed the change below to adhere to the RFC standards and therefore, emails to multiple recipients that
use the addRecipient method will fail to deliver.

Only one of each type of header is permitted.  We will no longer support duplicate headers for the following:

from
sender
reply-to
to
cc
bcc
x-smtpapi

Below is a snippet of the GEL script used for emails which will have duplicate headers in the email and will fail

<core:catch escapeText="false" var="exception">
<core:invokeStatic className="javax.mail.Session" method="getInstance" var="mailSession">
<core:arg type="java.util.Properties" value="${props}"/>
<core:arg type="javax.mail.Authenticator" value="${clarity_auth}"/>
</core:invokeStatic>
<core:set value="${mailSession.setDebug(debug)}" var="void"/>
<core:new className="javax.mail.internet.MimeMessage" var="message">
<core:arg type="javax.mail.Session" value="${mailSession}"/>
</core:new>
<core:set value="${V_EMAIL_SUBJECT} ${V_PROJ_CODE}" var="v_Email_Full_Subject"/>
<core:set value="${message.setSubject(v_Email_Full_Subject)}" var="void"/>
<core:new className="javax.mail.internet.InternetAddress" var="Sender">
<core:arg type="java.lang.String" value="${Sender}"/>
</core:new>
<core:set value="${message.setFrom(Sender)}" var="void"/>
<core:invokeStatic className="java.lang.Class" method="forName" var="rt">
<core:arg type="java.lang.String" value="javax.mail.Message$RecipientType"/>
</core:invokeStatic>
<core:set value="${rt.getField('TO')}" var="rt"/>
<core:set value="${rt.TO}" var="rt"/>
<core:forEach items="${v_BUPS_Email}" var="thisRecipient">
<core:new className="javax.mail.internet.InternetAddress" var="sendToEmail">
<core:arg type="java.lang.String" value="${thisRecipient}"/>
</core:new>
<core:set value="${message.addRecipient(rt, sendToEmail)}" var="void"/>
</core:forEach>

Resolution

The email code in the GEL script will have to be modified to use the following tags:

<gel:email>
<email:email>

The other option is to use setRecipient Java method instead of the addRecipient method. 

Additional Information

https://stackoverflow.com/questions/37236675/multiple-headers-issue-with-javamail-addrecipient-method