import smtplib
from email.mime.text import MIMEText
from email.header import Header
## args @title 标题
## args @content 内容
def mailfx_(title, content):
mail_host = 'smtp.qq.com'
# 发件箱
mail_user = ''
# 口令
mail_pass = ''
# 发送人
sender = ''
# 收件人
receivers = ['xxx@qq.com','bbb@aa.com']
message = MIMEText(content, 'plain', 'utf-8')
message['From'] = Header("python", 'utf-8')
message['To'] = Header("news", 'utf-8')
subject = title
message['Subject'] = Header(subject, 'utf-8')
print('
发送邮件中....')
try:
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 25) # 25 为 SMTP 端口号
smtpObj.login(mail_user,mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print ("邮件发送成功")
except smtplib.SMTPException:
print ("Error: 无法发送邮件")