python使用smtplib模块通过gmail发送邮件,pythonsmtplib,import smtpl
文章由Byrx.net分享于2019-03-23 08:03:13
python使用smtplib模块通过gmail发送邮件,pythonsmtplib,import smtpl
import smtplibfrom email.MIMEMultipart import MIMEMultipartfrom email.MIMEText import MIMETextfromaddr = '[email protected]'toaddr = '[email protected]'text = 'test email message sent from Python code'username = 'fromaddruser'password = 'fromaddrpassword'msg = MIMEMultipart()msg['From'] = fromaddrmsg['To'] = toaddrmsg['Subject'] = 'Test'msg.attach(MIMEText(text))server = smtplib.SMTP('smtp.gmail.com:587')server.ehlo()server.starttls()server.ehlo()server.login(username, password)server.sendmail(fromaddr, toaddr, msg.as_string())server.quit()
评论关闭