具体参考代码:
#!/usr/bin/env python # encoding: utf-8 import smtplib from email.mime.text import MIMEText class MyEmail: def __init__(self, subject, body): self.subject = subject self.body = body self.host = ‘smtp.qq.com‘ self.port = 465 self.sender = ‘sender@qq.com‘ self.pwd = ‘password‘ self.receiver = ‘receiver@qq.com‘ def send_email(self): msg = MIMEText(self.body, ‘plain‘, ‘utf-8‘) msg[‘subject‘] = self.subject msg[‘from‘] = self.sender msg[‘to‘] = self.receiver s = smtplib.SMTP_SSL(self.host, self.port) s.login(self.sender, self.pwd) s.sendmail(self.sender, self.receiver, msg.as_string()) if __name__ == ‘__main__‘: my_email = MyEmail(‘这是一封测试邮件‘, ‘这是一封测试邮件,请不要回复,谢谢‘) my_email.send_email()
本文出自 “许大树” 博客,谢绝转载!
原文地址:http://abelxu.blog.51cto.com/9909959/1873328