My email is feasible, the code is as follows
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
class SendMail(object):
def __init__(self, mail_title, mail_contain):
self.sender='sender email'
self.accepter='accepter email'
self.mail_title = mail_title
self.mail_contain = mail_contain
def send_data(self):
try:
msg = MIMEText(self.mail_contain, 'html', 'utf-8')
msg['From'] = formataddr(["sender name", self.sender])
msg['To'] = ";".join(self.accepter)
msg['Subject'] = self.mail_title
server = smtplib.SMTP_SSL("smtp host",465)
server.login(self.sender, "password")
server.sendmail(self.sender, self.accepter, msg.as_string())
server.quit()
except Exception as e:
print(e, 'send fail....')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…