标签:需要 str self col smtplib div __name__ utf-8 class
使用qq邮箱发送邮件,需要申请qq邮箱授权码
# coding=utf-8 import smtplib,sys from email.mime.text import MIMEText class Msmtp(): def __init__(self, target, subject, content):#收件人、标题、内容 self.msg_from = ‘发出邮件的邮箱‘ self.password = ‘邮箱的授权码‘ self.sender = smtplib.SMTP_SSL("smtp.qq.com", 465) self.msg_to = target self.subject = subject self.content = content def _login(self): self.sender.login(self.msg_from, self.password) def _msg(self): self.msg = MIMEText(self.content) self.msg[‘Subject‘] = self.subject self.msg[‘From‘] = self.msg_from self.msg[‘To‘] = self.msg_to def send_mail(self): self._login() self._msg() self.sender.sendmail(self.msg_from, self.msg_to, self.msg.as_string()) self.sender.quit() if __name__ == ‘__main__‘: a = Msmtp(sys.argv[1], sys.argv[2], sys.argv[3]) a.send_mail()
调用: python send.py 目标邮箱 标题 邮件内容(空格隔开)
标签:需要 str self col smtplib div __name__ utf-8 class
原文地址:https://www.cnblogs.com/lurenjia1994/p/9485997.html