import smtplib #发邮件
from email.mime.text import MIMEText #邮件文本
class SendMail:
def __init__(self,SMTPsever,Sender,password ):
self.SMTPsever = SMTPsever # 服务器
self.Sender = Sender # 邮件发送方
self.password = password # 密码
self.mailsever = smtplib.SMTP(self.SMTPsever, 25) # 邮件服务器端口25
self.mailsever.login(self.Sender, self.password) # 登陆
def Send(self,Message,title,maillist):
msg = MIMEText(Message) # 转化为邮件文本格式
msg["Subject"] =title # 邮件标题
msg["From"] = self.Sender # 邮件发送者
msg["To"] = "jieshou@163.com" # 邮件接收方
self.mailsever.sendmail(self.Sender,
maillist,
msg.as_string())
def exit(self): #可以通过析构函数完成
self.mailsever.quit()
sender1= SendMail("smtp.163.com","fasongzhe@163.com","123456")
sender1.Send("邮件内容 ","题目",["jieshoufang1@163.com","jieshoufang2@163.com"])
sender1.exit()
Python 邮件发送类
最新推荐文章于 2022-12-18 15:49:13 发布