最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】python中SMTP发送qq邮件出错:smtplib.SMTPAuthenticationError 530 Must issue a STARTTLS command first

Python crifan 6989浏览 0评论

折腾:

【已解决】python中smtp用qq发送邮件出错:smtplib.SMTPAuthenticationError 530 Error A secure connection is required

期间,再去试试587,结果至少可以继续运行了:

结果:

    smtpObj.login(sender, senderPassword)

  File “/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py”, line 622, in login

    raise SMTPAuthenticationError(code, resp)

smtplib.SMTPAuthenticationError: (530, ‘Must issue a STARTTLS command first.’)

python smtp qq邮箱

How to send an email with Gmail as provider using Python? – Stack Overflow

Python smtplib使用实例:网易邮箱向QQ邮箱发送邮件-香飘叶子-51CTO博客

使用Python登录QQ邮箱发送QQ邮件 – 简书

Python用QQ邮箱发送邮件时授权码问题 – CSDN博客

使用Python登录QQ邮箱发送QQ邮件

Python & Email,附上用 Python 发送 QQ 邮箱邮件的代码

使用QQ邮箱发送email(Python) – leetao94 – 博客园

看到有:

s = smtplib.SMTP_SSL(“smtp.qq.com“, 465)

所以去搜:

python smtp SMTP ssl

20.12. smtplib — SMTP protocol client — Python 2.7.14 documentation

python模块之smtplib: 用python发送SSL/TLS安全邮件 – CSDN博客

果然是有单独的:

smtplib.SMTP_SSL

所以代码改为:

if useSSL:

    smtpObj = smtplib.SMTP_SSL(smtpServer, smtpPort)

else:

    smtpObj = smtplib.SMTP(smtpServer, smtpPort)

然后就发送成了,开了debug的smtp的log是:

send: ‘ehlo licrifandeMacBook-Pro.local\r\n’

reply: ‘250-smtp.qq.com\r\n’

reply: ‘250-PIPELINING\r\n’

reply: ‘250-SIZE 73400320\r\n’

reply: ‘250-AUTH LOGIN PLAIN\r\n’

reply: ‘250-AUTH=LOGIN\r\n’

reply: ‘250-MAILCOMPRESS\r\n’

reply: ‘250 8BITMIME\r\n’

reply: retcode (250); Msg: smtp.qq.com

PIPELINING

SIZE 73400320

AUTH LOGIN PLAIN

AUTH=LOGIN

MAILCOMPRESS

8BITMIME

send: ‘AUTH PLAIN ADg0NDgzNDIzQHFxLmNvbQB3d2dsY2RyaHR4YWhiaGdq\r\n’

reply: ‘235 Authentication successful\r\n’

reply: retcode (235); Msg: Authentication successful

send: u’mail FROM:<[email protected]> size=1000\r\n’

reply: ‘250 Ok\r\n’

reply: retcode (250); Msg: Ok

send: u’rcpt TO:<[email protected]>\r\n’

reply: ‘250 Ok\r\n’

reply: retcode (250); Msg: Ok

send: u’rcpt TO:<[email protected]>\r\n’

reply: ‘250 Ok\r\n’

reply: retcode (250); Msg: Ok

send: ‘data\r\n’

reply: ‘354 End data with <CR><LF>.<CR><LF>\r\n’

reply: retcode (354); Msg: End data with <CR><LF>.<CR><LF>

data: (354, ‘End data with <CR><LF>.<CR><LF>’)

send: ‘Content-Type: text/html; charset=”utf-8″\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: base64\r\nFrom: =?utf-8?b?56S86LKMUVEgPDg0NDgzNDIzQHFxLmNvbT4=?=\r\nTo: =?utf-8?b?PT91dGYtOD9xP0NyaWZhbjIwMDM/PSA8Y3JpZmFuMjAwM0AxNjMuY29tPiwg?=\r\n =?utf-8?b?PT91dGYtOD9iPzVZV0w1NUdlNklxcz89IDxhZG1pbkBjcmlmYW4uY29tPg==?=\r\nSubject: =?utf-8?b?W+S7t+agvOmrmF0gdGl0bGUgaW5jbHVl5Lit5paHIERlbGwgWFBTIDEzIFhQ?=\r\n =?utf-8?q?S_9360_Laptop_PC?=\r\n\r\nCjxodG1sPgogICAgPGJvZHk+CiAgICAgICAgPGgxPlvku7fmoLzpq5hdIHRpdGxlIGluY2x1ZeS4\r\nreaWhyBEZWxsIFhQUyAxMyBYUFMgOTM2MCBMYXB0b3AgUEM8L2gxPgogICAgICAgIDxwPk5vdCBi\r\ndXkgPGEgaHJlZj0iaHR0cHM6Ly93d3cubWljcm9zb2Z0LmNvbS9lbi11cy9zdG9yZS9kL2RlbGwt\r\neHBzLTEzLXhwcy05MzYwLWxhcHRvcC1wYy84cTE3Mzg0Z3J6MzcvR1Y1RD9hY3RpdmV0YWI9cGl2\r\nb3QlMjUzYW92ZXJ2aWV3dGFiIj50aXRsZSBpbmNsdWXkuK3mlocgRGVsbCBYUFMgMTMgWFBTIDkz\r\nNjAgTGFwdG9wIFBDPC9hPiBmb3IgY3VycmVudCBwcmljZSA8Yj4kNjk5LjAwPC9iPiAmZ3Q7IGV4\r\ncGVjdGVkIHByaWNlIDxiPiQ1OTkuMDA8L2I+PC9wPgogICAgICAgIDxwPlNvIHNhdmUgZm9yIGxh\r\ndGVyIHByb2Nlc3M8L3A+CiAgICA8L2JvZHk+CjwvaHRtbD4K\r\n.\r\n’

reply: ‘250 Ok: queued as \r\n’

reply: retcode (250); Msg: Ok: queued as

data: (250, ‘Ok: queued as’)

对应的message为:

Content-Type: text/html; charset=”utf-8″

MIME-Version: 1.0

Content-Transfer-Encoding: base64

From: =?utf-8?b?56S86LKMUVEgPDg0NDgzNDIzQHFxLmNvbT4=?=

To: =?utf-8?b?PT91dGYtOD9xP0NyaWZhbjIwMDM/PSA8Y3JpZmFuMjAwM0AxNjMuY29tPiwg?=

=?utf-8?b?PT91dGYtOD9iPzVZV0w1NUdlNklxcz89IDxhZG1pbkBjcmlmYW4uY29tPg==?=

Subject: =?utf-8?b?W+S7t+agvOmrmF0gdGl0bGUgaW5jbHVl5Lit5paHIERlbGwgWFBTIDEzIFhQ?=

=?utf-8?q?S_9360_Laptop_PC?=

CjxodG1sPgogICAgPGJvZHk+CiAgICAgICAgPGgxPlvku7fmoLzpq5hdIHRpdGxlIGluY2x1ZeS4

reaWhyBEZWxsIFhQUyAxMyBYUFMgOTM2MCBMYXB0b3AgUEM8L2gxPgogICAgICAgIDxwPk5vdCBi

dXkgPGEgaHJlZj0iaHR0cHM6Ly93d3cubWljcm9zb2Z0LmNvbS9lbi11cy9zdG9yZS9kL2RlbGwt

eHBzLTEzLXhwcy05MzYwLWxhcHRvcC1wYy84cTE3Mzg0Z3J6MzcvR1Y1RD9hY3RpdmV0YWI9cGl2

b3QlMjUzYW92ZXJ2aWV3dGFiIj50aXRsZSBpbmNsdWXkuK3mlocgRGVsbCBYUFMgMTMgWFBTIDkz

NjAgTGFwdG9wIFBDPC9hPiBmb3IgY3VycmVudCBwcmljZSA8Yj4kNjk5LjAwPC9iPiAmZ3Q7IGV4

cGVjdGVkIHByaWNlIDxiPiQ1OTkuMDA8L2I+PC9wPgogICAgICAgIDxwPlNvIHNhdmUgZm9yIGxh

dGVyIHByb2Nlc3M8L3A+CiAgICA8L2JvZHk+CjwvaHRtbD4K

【总结】

此处python中用smtp发送邮件,结果报错:

<code>smtplib.SMTPAuthenticationError: (530, 'Must issue a STARTTLS command first.')
</code>

的原因是:

QQ邮箱中用了SSL的465(或587)端口,结果smtp库调用是却是用的非SSL的函数:

<code>smtplib.SMTP(smtpServer, smtpPort)
</code>

换成:

<code>smtpObj = smtplib.SMTP_SSL(smtpServer, 465)
</code>

即可。

转载请注明:在路上 » 【已解决】python中SMTP发送qq邮件出错:smtplib.SMTPAuthenticationError 530 Must issue a STARTTLS command first

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.187 seconds, using 22.11MB memory