Amazon SES SMTP Python Usage

综合编程 2018-05-26 阅读原文

I am trying to diagnose why sending email through Amazon SES is not working via python.

The following example demonstrates the problem, where user
and pass
are set to the appropriate credentials.

>>> import smtplib
>>> s = smtplib.SMTP_SSL("email-smtp.us-east-1.amazonaws.com", 465)
>>> s.login(user, pw)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/smtplib.py", line 549, in login
    self.ehlo_or_helo_if_needed()
  File "/usr/lib/python2.6/smtplib.py", line 510, in ehlo_or_helo_if_needed
    (code, resp) = self.helo()
  File "/usr/lib/python2.6/smtplib.py", line 372, in helo
    (code,msg)=self.getreply()
  File "/usr/lib/python2.6/smtplib.py", line 340, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed

This message is not particularly useful, and have tried other vraiations, but can't seem to get it to work.

I can send email using my thunderbird email client with these settings, so my assumption is that I am mission something TLS-related.

I don't think SMTP_SSL works anymore with SES. One must use starttls()

smtp = smtplib.SMTP("email-smtp.us-east-1.amazonaws.com")
smtp.starttls()
smtp.login(SESSMTPUSERNAME, SESSMTPPASSWORD)
smtp.sendmail(me, you, msg)
Hello, buddy!

责编内容by:Hello, buddy!阅读原文】。感谢您的支持!

您可能感兴趣的

Just another AI trying to predict the stock market... Learning how to build Machine learning models is neither a straightforward, nor an easy task. I spent the last month or ...
No module named 'urllib.request'; '... 想学爬虫urllib的设置代理服务器,于是把之前跳过没学的urllib捡起来,敲了段简单的代码,如下 import urllib.requesturl = "http://www.baidu.com" data = urllib....
reticulate – another step towards a multilingual a... R, Julia, Python – todays data scientists have the choice between numerous different programming languages, each with...
廖老师的Python教程——Python简介 一直想了解下Python,今儿在外面办事排队的时候,打开了廖老师的官网,找到了Python教程。虽然只是一篇关于Python的简介,但是通过将Python的特性与C进行对比,很生动地归纳了Python的一些特性。因为之前花过时间学习C,所...
大四学长手把手教我们从零开始利用Python开发微信公众号!已学会... 在一般的使用中,我们可以通过设置关键字实现一些基本的自动回复功能,但是这样的关键字回复远远不能满足我们的实际需求,比如我们要实现一个查快递的功能,必然是要通过调用快递接口对不同用户的不同输入给出不同的输出结果,在这样的情况下...