我可以将亚马逊的SES与Symfony2和Swiftmailer Bundle一起使用吗?

use*_*058 7 amazon-ec2 swiftmailer symfony amazon-ses

我正在亚马逊的ec2上运行一个运行64位版本CentOS的网站.

该网站有一个简单的联系我们表格,需要在提交时向几个地址发送电子邮件(非常基本).

有没有人使用亚马逊的SES与Symfony2和Swiftmailer捆绑?如果是这样,您是否建议使用SES或更传统的电子邮件服务器进行此类任务?

Phi*_*ber 13

可以通过SES发送带有swiftmailer库附带的本机SMTP传输的电子邮件.以下示例使用版本4.2.2进行测试.

Amazon SES 要求使用TLS加密.

Swift_SmtpTransport通过将tls作为第三个构造函数参数传递,可以将传输类配置为使用TLS加密:

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('example@example.org'))
    ->setTo(array('example@example.org' => 'John Doe'))
    ->setBody('Here is the message itself')
;

// Send the message
$result = $mailer->send($message);
Run Code Online (Sandbox Code Playgroud)

在Symfony2中,您可以将swiftmailer服务配置为使用TLS加密:

# 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
Run Code Online (Sandbox Code Playgroud)

直接从安装在EC2实例上的邮件服务器发送电子邮件并不十分可靠,因为EC2 IP地址可能被列入黑名单.建议使用受信任的邮件服务器,因此使用SES似乎是一个好主意.


tot*_*tas 8

通过Symfony2通过SES发送邮件对我来说没有开箱即用,因为我在config.yml中配置了spool选项.

我偶然发现的另一个问题是港口.端口25和587工作正常,但465让我超时.

并且重要的是你使用正确的SMTP服务器,起初我使用的是us-east-1(因为我从一个例子中复制了它)虽然我的SMTP实际上是email-smtp.eu-west-1.amazonaws.com

所以这是我当前的配置:

parameters:
    mailer_transport: smtp
    mailer_host: email-smtp.eu-west-1.amazonaws.com
    mailer_user: AWS_ACCESS_KEY
    mailer_password: AWS_SECRET_KEY
    mailer_encryption: tls
    mailer_port: 587

swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    username:  %mailer_user%
    password:  %mailer_password%
    encryption: "%mailer_encryption%"
    port: %mailer_port%
    auth_mode:  login
Run Code Online (Sandbox Code Playgroud)

我在命令行上执行以下命令找到了问题:

php app/console swiftmailer:debug
Run Code Online (Sandbox Code Playgroud)


Vic*_*ari 1

如果您可以坚持免费套餐限制(每日 2K 条消息),我绝对建议您坚持使用 SES 而不是传统的电子邮件服务器。它简单、易于与大多数平台集成,并且您可以消除电子邮件服务器的维护和运营成本(虽然很小,但它们仍然存在)。当然,使用 SES 时仍然存在数据传输成本,正如您在Amazon SES 定价上看到的那样,但这也可能适合您的需求。