So, today Amazon debuted Simple Email Service. The gist of it is, send mail with them instead of your own servers. Like a feature reduced SendGrid or Postmark.
Not a lot of stuff out there for it so I thought I’d jump the gun a bit and write a transport for PHP’s Swiftmailer. If you have to send e-mail from your sever and from PHP, Swiftmailer is your best friend.
Never dug into Swiftmailer’s guts before, but it’s pretty well laid out. All you have to do for a new transport is implement the send method of the Transport interface and you are done.
I knocked mine together pretty quick, and the only code I cribbed was the HMAC code from php-aws, because AWS was rejecting the output from hash_hmac. (Which I literally just figured out while I wrote that paragraph. Works now.)
So how hard is it to use? Easy as any other transport in Swiftmailer.
<?phprequire_once'lib/swift_required.php';//Create the Transport$transport=new Swift_AWSTransport('AWS_ACCESS_KEY','AWS_SECRET_KEY');//Create the Mailer using your created Transport$mailer= Swift_Mailer::newInstance($transport);//Create the message$message= Swift_Message::newInstance()->setSubject("What up?")->setFrom(array('you@yourdomain.com'))->setTo(array('them@theirdomain.com'))->setBody("
<p>
Dude, I'm <b>totally</b> sending you email via AWS.
</p>
",'text/html');$mailer->send($message);
So, yeah, it works.
I know there is a ton of stuff I didn’t implement that I need to before this could be “production” ready, but it was a very satisfying little project.