Sending emails to multiple receipients with Amazon SES

After reading through a ton of documentation posts and forum topics for Amazon SES about this issue, I finally found this post about the string list format that helped me be able to send an email with Amazon SES's sendmail API to multiple recipients.

Every way I tried getting this working, I was receiving errors like InvalidParameter for the sender, Unexpected list element termination for the error code, etc.

Normally, when sending email, you can either pass a single address or multiple addresses as a string, and you'll be fine:

  • Single Address: John Doe <johndoe@example.com>
  • Multiple Addresses: John Doe <johndoe@example.com>, Jane Doe <janedoe@example.com>

...just add in a comma between each address, and you're golden. Amazon's SES API documentation says you can pass a 'string/array' for the 'ToAddresses' parameter, and those addresses will be sent an email. They're kinda lacking in implementation details, though, and it took some wrangling to find out that, using Amazon's PHP API class, I had to prepare my addresses like so:

For normal (single) email addresses, I could just go:

<?php
  $destination
= CFComplexType::map(array(
   
'ToAddresses' => 'John Doe <johndoe@example.com>',
  ));
?>

(The $destination parameter would be passed into $ses->send_mail).

However, for multiple email addresses, you must pass in an array, with the following structure, and pass that to the CFComplexType object:

<?php
  $to
= array(
   
'member' => array(
     
0 => 'John Doe <johndoe@example.com>',
     
1 => 'Jane Doe <janedoe@example.com>',
    ),
  );

 
$destination = CFComplexType::map(array(
   
'ToAddresses' => $to,
  ));
?>

I don't know why Amazon can't just accept a normal string with commas designating recipients, as that would make life easier, imo, but oh well.

Comments

Just a question about this... will both users receive both email addresses in the "TO:" line of the email? What about if I want to send them as BCC (blind carbon copy)?
Thanks.

Yes - if you want to send them as BCC, add the addresses as BCCAddresses instead of TOAddresses. (You still need to have at least one address in the TOAddresses field, though).

Thanks! Was pulling my hair out trying to add additional addresses. Finally stumbled upon your blog which really helped.

What happens when you add one recipient multiple times to the array? Is SES smart enough to deduplicate?

Duplicate entries could happen by coded triggers..

Thanks