Monthly Archives: May 2011

AmazonSES and custom mail headers

A user pinged me this morning asking whether or not it was possible to set the fail-to email address when a message was bounced when using the AmazonSES API wrapper.  This is accomplished by setting the Return-Path header in the AmazonSES API wrapper.  This header is left empty by default but setting it is quite easy.  Here is an example of setting it when the component is initialized:

 public any function init(required String pathToCredentials) hint = "I initialize the gateway" {
  variables.instance = {};
  instance['awsCredentials'] = createObject("java", "").init(arguments.pathToCredentials);
  instance['credentials'] = createObject("java", "com.amazonaws.auth.PropertiesCredentials").init(instance.awsCredentials);
  instance['props'] = createObject("java", "java.util.Properties");
  instance.props.setProperty("mail.transport.protocol", "aws");
  instance.props.setProperty("", instance.credentials.getAWSAccessKeyId());
  instance.props.setProperty("", instance.credentials.getAWSSecretKey());
  instance['lastUpdated'] = now();
  instance['statsRefreshTimeout'] = 5;
  instance['supportedHeaders'] = listToArray("Accept-Language,Bcc,Cc,Comments,Comment-Type,Content-Transfer-Encoding,Content-ID,Content-Description,Content-Disposition,Content-Language,Date,DKIM-Signature,DomainKey-Signature,From,In-Reply-To,Keywords,List-Archive,List-Help,List-Id,List-Owner,List-Post,List-Subscribe,List-Unsubscribe,Message-Id,MIME-Version,Received,References,Reply-To,Return-Path,Sender,Subject,Thread-Index,Thread-Topic,To,User-Agent");
  instance['endPoint'] = "";
  instance['sendQuota'] = getSendQuotaService();
  instance['sendStats'] = getSendStatisticsService();
  instance['verifiedEmailAddresses'] = listVerifiedEmailAddressesService();
  instance['sendHeaders'] = {'Return-Path'=''};
  return this;

You can also call the setHeaders(required struct headers) method to pass the default header you want to use with all emails.  If you want bounces sent to the sender of the message it can also be handled in the sendEMail() method like so:

messageObj.addHeader("Return-Path", createObject("java", "javax.mail.internet.InternetAddress").init(messageFrom).toString());

AmazonSES supports quite a few headers out of the box as well as letting set your own custom headers as well.  If there is enough interest I will go ahead and integrate the Return-Path header into the code base.   Should it be set by default or would you rather set it yourself?  Let me know.

AmazonSES API 0.1.6

I finally got around to installing the developer edition of ACF tonight.  I have gotten several emails about having to make modifications to AmazonSES to get it working correctly with ACF so I took a little bit of time and got all of this corrected.   The fixed version is now on github.