如何使用smtplib实现python自动编译器?

2024-05-19 17:03:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用smtplib编写python auto-mailer。我已经让它运行了,但我一直在执行我的except语句

代码看起来像这样

    sender = ['..........@gmail.com']
    receivers = ['.......@gmail.com']

    subject = "does this work?"
    message = "this is a cool email"

    try:
        server = smtplib.SMTP('smtp.gmail.com:587')
        server.ehlo()
        server.starttls()
        server.sendmail(sender, receivers, message)
        print("Successfully sent email")
        server.quit()
    except smtplib.SMTPException:
        print("Error: unable to send email")

感谢您的帮助

编辑:堆栈跟踪如下

Traceback (most recent call last):
  File "C:/Users/......py", line 38, in <module>
    email_protocol()
  File "C:/Users/....py", line 33, in email_protocol
    server.sendmail(sender, receivers, message)
  File "C:\Users\...\lib\smtplib.py", line 867, in sendmail
    raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (530, b'5.7.0 Authentication Required. Learn more at\n5.7.0  https://support.google.com/mail/?p=WantAuthError c33sm2599297qtb.76 - gsmtp', ['....@gmail.com'])

Process finished with exit code 1

Tags: inpycommessageserveremaillineusers