使用Python发送邮件
from email.mime.multipart import MIMEMultipart
from email.header import Header
import smtplib
from email.mime.text import MIMEText
class sendTestReport():
def sendTestReport(self):
smtp = smtplib.SMTP("smtp.qq.com")
smtp.login("邮箱账号","邮箱密码")
sendTestReportFile = open("附件本地目录", "r").read()
att = MIMEText(sendTestReportFile,"utf-8")
att["Content-Type"] = "application/octet-stream"
att.add_header('Content-Disposition','attachment',filename = Header('中文文件名','utf-8').encode())
msgRoot = MIMEMultipart()
msgRoot.attach(MIMEText("content","html","utf-8"))
msgRoot["Subject"] = "subject"
msgRoot["From"] = "发件人地址"
msgRoot["To"] = "收件人地址"
msgRoot.attach(att)
smtp.sendmail(msgRoot["From"],msgRoot["To"],msgRoot.as_string())
smtp.close()
if __name__ == '__main__':
sendTestReport_Obj = sendTestReport()
sendTestReport_Obj.sendTestReport()