给gmai邮箱发邮件的一段python小脚本

import smtplib
from email.MIMEText import MIMEText

fromaddr = '[email protected]'
toaddrs  = ['[email protected]','[email protected]']

msg = MIMEText("test content", "plain")
msg['Subject']= "test subject" # 邮件主题要这么加,真麻烦


username = 'gmail_user_name'
password = 'gmail_user_password'

server = smtplib.SMTP('smtp.gmail.com')
server.ehlo()
server.starttls()
server.ehlo()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg.as_string())
server.quit()

你可能感兴趣的:(python,脚本,Gmail)