It is possible to send email via SES with the native SMTP transport shipped with the swiftmailer library. Examples below were tested using version 4.2.2.
Amazon SES requires usage of TLS encryption.
Swift_SmtpTransport
transport class can be configured to use TLS encryption by passing tls as the third constructor argument:
require_once './vendor/swiftmailer/swiftmailer/lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance(
'email-smtp.us-east-1.amazonaws.com',
25,
'tls'
)
->setUsername('AWS_ACCESS_KEY')
->setPassword('AWS_SECRET_KEY')
;
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('[email protected]'))
->setTo(array('[email protected]' => 'John Doe'))
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
In Symfony2, you can configure the swiftmailer
service to use TLS encryption:
# app/config/config.yml
swiftmailer:
transport: smtp
host: email-smtp.us-east-1.amazonaws.com
username: AWS_ACCESS_KEY
password: AWS_SECRET_KEY
encryption: tls
Sending emails directly from a mailserver installed on an EC2 instance is not very reliable as EC2 IP addresses may be blacklisted. It is recommended to use a trusted mailserver so using SES seems to be a good idea.