python 利用smtplib发送邮件

  
import smtplib
from email.mime.text import MIMEText

mailserver = "smtp.qq.com"
from_addr = "[email protected]"
to_addrs = "[email protected]"

user = "[email protected]"
password = "xxxx"

msg = MIMEText('hello world')
msg['Subject'] = 'I miss you'
msg['From'] = 'abc'
msg['To'] = 'def'

svr = smtplib.SMTP(mailserver)
svr.set_debuglevel(1)
svr.login(user, password)
svr.sendmail(from_addr, to_addrs, msg.as_string())
svr.quit()

要登录成功qq邮箱,必须先在邮箱设置一下支持smtp/pop登录

你可能感兴趣的:(python,String,qq,user,import)