I think yesterday Amazon announced SMTP support for SES (Simple Email Service).
我想昨天亚马逊宣布对SES(简单电子邮件服务)的SMTP支持。
I tried to send SMTP email with Codeigniter with no luck.
我试着用Codeigniter发送SMTP电子邮件但没有运气。
I have a verified sender and everything looks good:
我有一个经过验证的发件人,一切都很好看:
$this->load->library('email');
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'email-smtp.us-east-1.amazonaws.com',
'smtp_user' => 'SMTP USERNAME',
'smtp_pass' => 'SMTP PASSWORD',
'smtp_port' => 465,
'mailtype' => 'html'
);
$this->email->initialize($config);
$this->email->print_debugger();
$this->email->from('verified_email_address@something.com', 'Test From');
$this->email->to('email@example.com', 'Test To');
$this->email->subject('Test');
$this->email->message('test');
$this->email->send();
I tried the folowing smtp_host:
我尝试了下面的smtp_host:
- email-smtp.us-east-1.amazonaws.com
- email-smtp.us-east-1.amazonaws.com
- tls://email-smtp.us-east-1.amazonaws.com
- TLS://email-smtp.us-east-1.amazonaws.com
- ssl://email-smtp.us-east-1.amazonaws.com
- SSL://email-smtp.us-east-1.amazonaws.com
When i echo the print_debugger() i get:
当我回显print_debugger()时,我得到:
220 email-smtp.amazonaws.com ESMTP SimpleEmailService-194655181
hello: 421 Timeout waiting for data from client.
These tests run on a mediatemple (gs) server.
这些测试在mediatemple(gs)服务器上运行。
5 个解决方案
#1
24
I got that timeout message until I added the line:-
我收到了超时消息,直到我添加了该行: -
$this->email->set_newline("\r\n");
I have my host set as ssl://email-smtp.us-east-1.amazonaws.com
我的主机设置为ssl://email-smtp.us-east-1.amazonaws.com
#2
5
public function enviar_email($para, $assunto, $mensagem, $formato='html'){
$this->CI->load->library('email');
$config['mailtype'] = $formato;
$config['useragent'] = 'Post Title';
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'tls://email-smtp.us-east-1.amazonaws.com';
$config['smtp_user'] = 'smtpuser';
$config['smtp_pass'] = 'smtppass';
$config['smtp_port'] = '465';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
$this->CI->email->initialize($config);
$this->CI->email->from('Your Verified Sender Email', 'Post Title');
$this->CI->email->to($para);
$this->CI->email->subject($assunto);
$this->CI->email->message($mensagem);
if($this->CI->email->send()):
return TRUE;
else:
$this->CI->email->print_debugger();
endif;
}
#3
4
I also needed to add the line
我还需要添加这一行
$config['smtp_crypto'] = 'tls';
to my config array
到我的配置数组
this is supported by CI 2.1.0 and greater
CI 2.1.0及更高版本支持此功能
#4
2
The setup that worked for me looks like this:
适合我的设置如下所示:
$test_config['protocol'] = 'smtp';
$test_config['smtp_host'] = 'ssl://email-smtp.us-east-1.amazonaws.com';
$test_config['smtp_port'] = '465';
$test_config['smtp_user'] = 'XXXXXXXXXXXXXXXXXXX';
$test_config['smtp_pass'] = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY';
$test_config['newline'] = "\r\n";
$this->email->initialize($test_config);
$this->email->from('from@test.com', 'From at Test.com');
$this->email->to('To@Test.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
The newline character must be set to "\r\n", and can bet set in the config file, if properly set as "\r\n", not '\r\n' as noted above.
换行符必须设置为“\ r \ n”,如果正确设置为“\ r \ n”,则可以在配置文件中设置,而不是如上所述'\ r \ n'。
#5
2
You need to do 3 things to get CI to work with Amazon Simple Email Service (SES)
您需要做三件事才能让CI与Amazon Simple Email Service(SES)一起使用
- Need to set
newline = \r\n
or you will get a timeout. - 需要设置换行符= \ r \ n或者您将获得超时。
- Need to set
smtp_crypto
to something. (New requirement) - 需要将smtp_crypto设置为某种东西。 (新要求)
- Need to make sure "from" email address is approved in Amazon SES. I made my "from" email address "no-reply@mydomain.com"
- 需要确保在Amazon SES中批准“来自”电子邮件地址。我发了“来自”电子邮件地址“no-reply@mydomain.com”
Additionally, you should set up DKIM for your "from" email address to prevent emails from getting put in spam folders. This involves going into Amazon SES -> Identity Management -> Email Addresses -> DKIM, hitting the enable button, and adding 3 DNS entries to your website's DNS.
此外,您应该为“发件人”电子邮件地址设置DKIM,以防止电子邮件被放入垃圾邮件文件夹。这涉及进入Amazon SES - >身份管理 - >电子邮件地址 - > DKIM,点击启用按钮,并在您网站的DNS中添加3个DNS条目。
No need to do anything special to set up SPF. The envelope domain amazonses.com passes SPF.
无需做任何特殊设置SPF。信封域amazonses.com通过SPF。
Finally, make sure to use "reply-to" if you want users to be able to reply to an e-mail address different from your approved "from" e-mail address.
最后,如果您希望用户能够回复与您批准的“来自”电子邮件地址不同的电子邮件地址,请务必使用“回复”。
Example working code:
工作代码示例:
$obj = &get_instance();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'email-smtp.us-west-2.amazonaws.com';
$config['smtp_user'] = 'USER';
$config['smtp_pass'] = 'PASS';
$config['smtp_port'] = '587';
$config['newline'] = "\r\n";
$config['smtp_crypto'] = 'tls';
$obj->email->initialize($config);
$obj->email->set_mailtype('html');
// don't html_escape email header variables
$obj->email->from(MV_FROM_EMAIL, $from_name);
$obj->email->reply_to($from_email, $from_name);
$obj->email->to($to);
$obj->email->subject($subject);
$obj->email->message($obj->load->view($path, html_escape($data), true));
$obj->email->send();
#1
24
I got that timeout message until I added the line:-
我收到了超时消息,直到我添加了该行: -
$this->email->set_newline("\r\n");
I have my host set as ssl://email-smtp.us-east-1.amazonaws.com
我的主机设置为ssl://email-smtp.us-east-1.amazonaws.com
#2
5
public function enviar_email($para, $assunto, $mensagem, $formato='html'){
$this->CI->load->library('email');
$config['mailtype'] = $formato;
$config['useragent'] = 'Post Title';
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'tls://email-smtp.us-east-1.amazonaws.com';
$config['smtp_user'] = 'smtpuser';
$config['smtp_pass'] = 'smtppass';
$config['smtp_port'] = '465';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
$this->CI->email->initialize($config);
$this->CI->email->from('Your Verified Sender Email', 'Post Title');
$this->CI->email->to($para);
$this->CI->email->subject($assunto);
$this->CI->email->message($mensagem);
if($this->CI->email->send()):
return TRUE;
else:
$this->CI->email->print_debugger();
endif;
}
#3
4
I also needed to add the line
我还需要添加这一行
$config['smtp_crypto'] = 'tls';
to my config array
到我的配置数组
this is supported by CI 2.1.0 and greater
CI 2.1.0及更高版本支持此功能
#4
2
The setup that worked for me looks like this:
适合我的设置如下所示:
$test_config['protocol'] = 'smtp';
$test_config['smtp_host'] = 'ssl://email-smtp.us-east-1.amazonaws.com';
$test_config['smtp_port'] = '465';
$test_config['smtp_user'] = 'XXXXXXXXXXXXXXXXXXX';
$test_config['smtp_pass'] = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY';
$test_config['newline'] = "\r\n";
$this->email->initialize($test_config);
$this->email->from('from@test.com', 'From at Test.com');
$this->email->to('To@Test.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
The newline character must be set to "\r\n", and can bet set in the config file, if properly set as "\r\n", not '\r\n' as noted above.
换行符必须设置为“\ r \ n”,如果正确设置为“\ r \ n”,则可以在配置文件中设置,而不是如上所述'\ r \ n'。
#5
2
You need to do 3 things to get CI to work with Amazon Simple Email Service (SES)
您需要做三件事才能让CI与Amazon Simple Email Service(SES)一起使用
- Need to set
newline = \r\n
or you will get a timeout. - 需要设置换行符= \ r \ n或者您将获得超时。
- Need to set
smtp_crypto
to something. (New requirement) - 需要将smtp_crypto设置为某种东西。 (新要求)
- Need to make sure "from" email address is approved in Amazon SES. I made my "from" email address "no-reply@mydomain.com"
- 需要确保在Amazon SES中批准“来自”电子邮件地址。我发了“来自”电子邮件地址“no-reply@mydomain.com”
Additionally, you should set up DKIM for your "from" email address to prevent emails from getting put in spam folders. This involves going into Amazon SES -> Identity Management -> Email Addresses -> DKIM, hitting the enable button, and adding 3 DNS entries to your website's DNS.
此外,您应该为“发件人”电子邮件地址设置DKIM,以防止电子邮件被放入垃圾邮件文件夹。这涉及进入Amazon SES - >身份管理 - >电子邮件地址 - > DKIM,点击启用按钮,并在您网站的DNS中添加3个DNS条目。
No need to do anything special to set up SPF. The envelope domain amazonses.com passes SPF.
无需做任何特殊设置SPF。信封域amazonses.com通过SPF。
Finally, make sure to use "reply-to" if you want users to be able to reply to an e-mail address different from your approved "from" e-mail address.
最后,如果您希望用户能够回复与您批准的“来自”电子邮件地址不同的电子邮件地址,请务必使用“回复”。
Example working code:
工作代码示例:
$obj = &get_instance();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'email-smtp.us-west-2.amazonaws.com';
$config['smtp_user'] = 'USER';
$config['smtp_pass'] = 'PASS';
$config['smtp_port'] = '587';
$config['newline'] = "\r\n";
$config['smtp_crypto'] = 'tls';
$obj->email->initialize($config);
$obj->email->set_mailtype('html');
// don't html_escape email header variables
$obj->email->from(MV_FROM_EMAIL, $from_name);
$obj->email->reply_to($from_email, $from_name);
$obj->email->to($to);
$obj->email->subject($subject);
$obj->email->message($obj->load->view($path, html_escape($data), true));
$obj->email->send();