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! (源链)。感谢您的支持!

您可能感兴趣的

Programiz: Python *args and **kwargs In programming, we define a function to make a reusable code that performs similar operation. To perform that operation, we call a function with the s...
Python: can not see an exception that la... I am running a unit test and I realize that there is an exception getting thrown. However, I am just not sure what exactly is getting thrown. from p...
【Python3网络爬虫】1.1-Python 3的安装 既然要用Python 3开发爬虫,那么第一步一定是安装Python 3。这里会介绍Windows、Linux和Mac三大平台下的安装过程。 1.1.1 相关链接 官方网站: http://python.org 下载地址: https://www.python.org/do...
一次简单的验证码识别以及思考 验证码(CAPTCHA)是“Completely Automated Public Turing test to tell Computers and Humans Apart”(全自动区分计算机和人类的图灵测试)的缩写,是一种区分用户是计算机还是人的公共全自动程序。可以防止:恶意破解密码、刷票、论...
Understand a simple multi-process script I am trying to understand how Python's multiprocessing module work. To do so, a made a very simple version of the code I'm working on and tried to...