电子邮件未发送。请告诉问题?

时间:2020-01-09 08:50:27

标签: python email automation smtp smtplib

请在代码中告知错误。输出始终为“未发送电子邮件”

import smtplib

port = 587
sender_mail = input("Enter your email address :  ")
sender_password = input("Enter your password :  ")
receiver_mail = input("Enter receiver's mail address :  ")
message = input("Enter the message you want to send ")

try:
    server = smtplib.SMTP("smtp.gmail.com",port)
    server.starttls()
    server.login(sender_mail,sender_password)
    server.sendmail(sender_mail,receiver_mail,message)
    print("Email sent successfully")
    server.quit()
except:
    print("Email not sent")
    server.quit()

1 个答案:

答案 0 :(得分:1)

更改您的except:以获得异常文本

 try:
    #Your code
 except Exception as e:
    print("Email not sent, Exception:", str(e))
    server.quit()
相关问题