用python写的自动转发邮件信息模板

# -*- coding:utf-8 -*-
#加密东西
def decrypt(key, s):
    c = bytearray(str(s).encode("gbk"))
    n = len(c)
    if n % 2 != 0:
        return ""
    n = n // 2
    b = bytearray(n)
    j = 0
    for i in range(0, n):
        c1 = c[j]
        c2 = c[j + 1]
        j = j + 2
        c1 = c1 - 65
        c2 = c2 - 65
        b2 = c2 * 16 + c1
        b1 = b2 ^ key
        b[i] = b1
    try:
        return b.decode("gbk")
    except:
        return "failed"
def sendmail(port):
    import pandas as pd
    import datetime
    import smtplib
    date=str(datetime.datetime.now())[:10]
    from email.mime.text import MIMEText
    from email.header import Header
    from email.mime.application import MIMEApplication
    from email.utils import formataddr
    from email.mime.multipart import MIMEMultipart
    try:
        data=pd.read_csv("/home/deploy/wangliang/file/000000_0",delimiter='	',names=['日期','城市','总投放数','3至7天','3至7天','7至15天','7至15天','15至30天','15至30天','30天以上','30天以上'])
        data.to_csv("/home/deploy/wangliang/file/闲置数据"+date+".csv",index=None)
    except:
        pass
    message=MIMEMultipart()
    mail_host = "smtp.exmail.qq.com"
    mail_user = "" #账号
    mail_pass =""  #密码
    sender = ''#发送人
    receivers = []#接收人列表
    # xlsxpart=MIMEApplication(open(u"/home/deploy/wangliang/file/闲置数据"+date+".csv",'rb').read().decode('utf-8').encode('gbk'))
    # xlsxpart.add_header('Content-Disposition','attachment',filename="xianzhi"+date+".csv")
    # message.attach(xlsxpart)   添加附件
    message['From'] = formataddr(["发送人昵称",'账号'])
    message['To'] = ";".join(receivers)
    subject = '主题'
    message['Subject'] = Header(subject, 'utf-8')
    textextpart= MIMEText("<font color=blue>Hello:<br>附件为,谢谢</font>",'html','utf-8') #文本信息
    message.attach(textextpart)
    message["Accept-Language"]="zh-CN"
    message["Accept-Charset"]="ISO-8859-1,utf-8"
    smtpbj = smtplib.SMTP_SSL()# SSL认证
    smtpbj.connect(mail_host,port) #连接
    smtpbj.login(mail_user, mail_pass)
    smtpbj.sendmail(sender, receivers, message.as_string())
if __name__=='__main__':
    sendmail(port=465)
原文地址:https://www.cnblogs.com/Willie-WangLiang/p/7853090.html