import sys
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from Utils.Log import Logger
from datetime import datetime
send_time = (datetime.now()).replace(microsecond=0)
Loger_Message = Logger()
def SendMails(JJR, SJR, next):
# 寄件人
sender =JJR # "779968531@qq.com"
# 权限验证(密码),来源:QQ邮箱内查询得到
pwd = "hormmuefyvhvbdjc"
# 收件人(接收邮件,可设置为你的QQ邮箱或者其他邮箱)
receivers = [SJR] # "779968531@qq.com"
# 三个参数:第一个为文本内容,第二个 plain 设置文本格式,第三个 utf-8 设置编码
message = MIMEText(next, 'plain', 'utf-8') # 邮件内容
message['From'] = Header("菜鸟教程", 'utf-8') # 发送者
message['To'] = Header("测试", 'utf-8') # 接收者
# 邮件标题
subject = 'Python SMTP 邮件测试'
message['Subject'] = Header(subject, 'utf-8')
try:
smtpObj = smtplib.SMTP("smtp.qq.com", 25) # 端口默认 25
smtpObj.login(sender, pwd)
smtpObj.sendmail(sender, receivers, message.as_string())
Loger_Message.loginfo("%s\t方法名\t%s:\t%s" % (send_time, sys._getframe().f_code.co_name, "邮件发送成功"))
except smtplib.SMTPException:
Loger_Message.loginfo("%s\t方法名\t%s:\t%s" % (send_time, sys._getframe().f_code.co_name, "邮件发送失败"))
# SendMails("779968531@qq.com", "779968531@qq.com", "邮件内容")
变量:
权限:pwd = “hormmuefyvhvbdjc”
发件人,收件人,邮件内容