通过python脚本发送电子邮件时的身份验证问题

时间:2016-12-12 09:08:09

标签: python-3.x

我按照以下步骤使用python脚本发送电子邮件 -

import smtplib
smtpUser='sint.15@gmail.com'
smtpPass='1234'
toAdd='ajit@gmail.com'
fromAdd=smtpUser
subject='Python test'
header='To:' +toAdd+'\n'+'From:'+fromAdd+'\n' +'Subject:'+ subject
body='From within a python script'

print( header + '\n'+ body)
s= smtplib.SMTP('smtp.gmail.com',587)
s.ehlo()
s.starttls()
s.ehlo()
s.login(smtpUser,smtpPass)
s.sendmail(fromAdd,toAdd,header +'\n' + body)
s.quit()

然后错误消息是 -

Traceback (most recent call last):
File "C:/Users/129/PycharmProjects/smtp.py", line 34, in    <module>
s.login(smtpUser,smtpPass)
File "C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\smtplib.py", line 652, in login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (501, b'5.5.2 Cannot Decode response q9sm74360527pfg.47 - gsmtp')
Process finished with exit code 1

有人可以解释一下我的错误是什么,如果我没错,那就与谷歌安全有关。

1 个答案:

答案 0 :(得分:0)

我用它来发送来自Gmail帐户的电子邮件:

services:
   nginx-main:
      image: nginx:latest
      ports:
         - "80:80"
      volumes:
         - ./nginx.conf:/etc/nginx/nginx.conf:ro
         - /var/log/nginx:/var/log/nginx
      external_links:
         - rahmanusta_wp
         - mysql_db
      container_name: nginx_main

看看here。它对我有用。