这是发送电子邮件的正确方法吗?蟒蛇

时间:2014-11-17 23:49:42

标签: python email smtp gmail

我只是想知道这是否是发送电子邮件的正确方法?

一切看起来应该是普通的电子邮件程序吗?

import smtplib

login_Info = ["testemailforthis@gmail.com", "Password"]
receivers = ["testemailforthis@gmail.com"]

message = """From: Me
To: People
Subject: Test email

Hi this is a test email :D"""

try:
    email_thing = smtplib.SMTP("smtp.gmail.com", 587)
    email_thing.ehlo()
    email_thing.starttls()
    email.login(login_Info[0], login_Info[1])
    email_thing.sendmail(login_Info[0], receivers, message)
    email_thing.close()
    print("The email was sent!")
except:
    print("The email was unable to send!")

0 个答案:

没有答案