简体   繁体   English

如何配置CakePHP 3.x以使用Amazon SES SMTP发送电子邮件?

[英]How to configure CakePHP 3.x to use Amazon SES SMTP to send out emails?

I have successfully created my SMTP credentials in AWS SES. 我已经在AWS SES中成功创建了SMTP凭证。

I have lifted my restrictions. 我解除了限制。

I have used the command line to test if my credentials are okay. 我已经使用命令行来测试我的凭据是否还可以。

They are. 他们是。

I am using CakePHP 3.2 but still unable to send out my emails. 我正在使用CakePHP 3.2,但仍然无法发送电子邮件。

The region I use is US West Oregon. 我使用的地区是美国俄勒冈州西部。 The host is email-smtp.us-west-2.amazonaws.com 主持人是email-smtp.us-west-2.amazonaws.com

How to test if credentials are okay via Command Line 如何通过命令行测试凭据是否还可以

  1. Open up your server terminal and type echo -n "YOUR SMTP USERNAME" | base64 打开服务器终端,然后键入echo -n "YOUR SMTP USERNAME" | base64 echo -n "YOUR SMTP USERNAME" | base64
  2. Copy paste the output somewhere. 复制将输出粘贴到某处。 You will need it. 您将需要它。 The output should end with = 输出应以=结尾
  3. Repeat step 1 and 2 for YOUR SMTP PASSWORD YOUR SMTP PASSWORD重复步骤1和2
  4. Copy paste the following into a text file but replace <whatever> as you deem fit. 复制以下内容,将其粘贴到文本文件中,然后根据需要替换<whatever>

Like this: 像这样:

AFTER 220 .... PASTE THE LINE BELOW:
EHLO <example.com>

AFTER 250 Ok PASTE THE LINE BELOW:
AUTH LOGIN

AFTER 334 VXNlcm5hbWU6:
<YOUR SMTP USERNAME encoded as base64 from step 1>

AFTER 334 UGFzc3dvcmQ6:
<YOUR SMTP PASSWORD encoded as base64 from step 3>

AFTER 235 Authentication successful.
MAIL FROM:<yourverifiedemail@example.com>

AFTER 250 Ok
RCPT TO:<yourverifiedemail@example.com>

AFTER 250 Ok
DATA

AFTER 354 End data with <CR><LF>.<CR><LF>    
Subject:Hello from Amazon SES!

This email was sent using the Amazon SES SMTP interface.
.
  1. Type openssl s_client -crlf -quiet -connect email-smtp.us-west-2.amazonaws.com:465 into your terminal 在终端中输入openssl s_client -crlf -quiet -connect email-smtp.us-west-2.amazonaws.com:465

  2. Follow the instructions in the text file. 请按照文本文件中的说明进行操作。

Once ascertained that credentials are good, now configure your cakephp 3.x 一旦确定凭据是好的,现在配置您的cakephp 3.x

Configure Cake 3.x 配置Cake 3.x

  • Open up your config/app.php 打开您的config/app.php

  • Find EmailTransport and add a new transport below default 查找EmailTransport并在默认值以下添加新的传输

Like this: 像这样:

'EmailTransport' => [
    'default' => [
        'className' => 'Mail',
        // The following keys are used in SMTP transports
        'host' => 'localhost',
        'port' => 25,
        'timeout' => 30,
        'username' => 'user',
        'password' => 'secret',
        'client' => null,
        'tls' => null,
    ],
    // START of what you need to add!!
    'AWS_SES' =>[
        'className' => 'Smtp', 
        'host' => 'email-smtp.us-west-2.amazonaws.com', 
        'port' => 587, // this is very important to be 587!! 
        'timeout' => 30,
        'username' => 'YOUR SMTP USERNAME',
        'password' => 'YOUR SMTP PASSWORD',
        'tls' => true, // this is also very important!!
    ]
    // END of what you need to add!!
],
  • Now look for Email in app.php and add a new profile below default 现在在app.php查找Email并在默认值下方添加新的配置文件

Like this: 像这样:

'Email' => [
    'default' => [
        'transport' => 'default',
        'from' => 'you@localhost',
        //'charset' => 'utf-8',
        //'headerCharset' => 'utf-8',
    ],
// START of what you need to add!
    'production' => [
        'transport' => 'AWS_SES',
        //'log' => true,
    ]
// END of what you need to add!
],
  • That's all for configuration! 这就是配置的全部!
  • Just call $email = new Email('production'); 只需调用$email = new Email('production'); at the appropriate place that you want. 在您想要的适当位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM