通过QQ邮箱发送邮件
#coding:utf8 import email import smtplib from email.mime.text import MIMEText from email.header import Header from email.mime.multipart import MIMEMultipart from email.mime.image import MIMEImage from email.mime.application import MIMEApplication import os sender = '2578201379@qq.com' receivers = 'xxxxxxxx@qq.com' subject = 'python test sendmail' smtpserver = 'smtp.qq.com' username = '2578201379@qq.com' password = '111111111' message = MIMEMultipart() message['From'] = sender message['To'] = receivers message['Subject'] = subject context = "<h1>大家好:</h1>这个是正文" message.attach(MIMEText('{0}'.format(context), 'plain', 'utf-8')) server = smtplib.SMTP_SSL() server.connect(smtpserver, '465') server.login(username, password) server.sendmail(sender, receivers, message.as_string()) server.quit()
发送结果: