1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- # Author renyupeng
- # coding=utf-8
- # @Time : 2021/11/30 6:02 下午
- # @Site :
- # @File : SendEmail.py
- # @Software: PyCharm
- # @contact: renyupeng@c-top.com.cn
- # @Tel 1501435553
- import smtplib
- import time
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- class SendEmail:
- @staticmethod
- def mail(content):
- try:
- # 邮件的内容
- my_sender = 'notice@c-top.com.cn' # 发件人邮箱账号
- my_pass = 'Hcst@2019' # 发件人邮箱授权码 / 腾讯企业邮箱请使用登陆密码
- recipients = ['liyuyi@c-top.com.cn', 'zhaoxian@c-top.com.cn', 'yumengmeng@c-top.com.cn'] # 收件人邮箱账号
- # content = "Please check the attachment. "
- msg = MIMEMultipart()
- msg['date'] = time.strftime('%a, %d %b %Y %H:%M:%S %z')
- msg.attach(MIMEText(content, 'html', 'utf-8'))
- # att = MIMEText(open(attachment, 'rb').read(), 'base64', 'utf8')
- # att["Content-Type"] = 'application/octet-stream'
- # att["Content-Disposition"] = 'attachment; filename="%s"' % attachment
- # msg.attach(att)
- # [发件人的邮箱昵称、发件人邮箱账号], 昵称随便
- msg['From'] = my_sender
- # [收件人邮箱昵称、收件人邮箱账号], 昵称随便
- msg['To'] = ",".join(recipients)
- # 邮件的主题,也就是邮件的标题
- msg['Subject'] = "人群分析报表数据异常监控"
- # 备注:这里使用的是QQ邮箱的服务器, 加入用腾讯企业邮箱作为发件人的话,请将"smtp.qq.com" 修改为 "smtp.exmail.qq.com"
- # 发件人邮箱中的SMTP服务器,qq端口是465
- # server = smtplib.SMTP_SSL("smtp.exmail.qq.com", port=465)
- server = smtplib.SMTP_SSL("smtp.exmail.qq.com", port=465)
- # (发件人邮箱账号、邮箱密码)
- server.login(my_sender, my_pass)
- # (发件人邮箱账号、收件人邮箱账号、发送邮件)
- server.sendmail(my_sender, recipients, msg.as_string())
- server.quit() # 关闭连接
- print("邮件发送成功")
- except Exception as e:
- print("邮件发送失败: ", e)
|