#!/usr/bin/python
# -*- coding:UTF-8 -*-
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
from email.header import Header
import sys
from email.mime.multipart import MIMEMultipart
def mail(recv_people):
mail_host = 'smtp.126.com'
mail_passwd = 'GMMVYVTTBJUVOGIC'
send_people = 'ligen_123@126.com'
# recv_people = '1694489278@qq.com'
msg = MIMEMultipart()
msg['from'] = formataddr(["李根",send_people])
msg['to'] = formataddr(["酱油人",recv_people])
msg['Subject'] = Header("第三次测试",'utf-8')
msg.attach(MIMEText('这是第三次测试','plain','utf-8'))
att1 = MIMEText(open('222.txt','rb').read(),'base64','utf-8')
att1["Content-Type"] = 'application/octet-stream'
att1["Content-Disposition"] = 'attachment;filename="222.txt"'
msg.attach(att1)
smtp = smtplib.SMTP_SSL("smtp.126.com",465)
smtp.login(send_people,mail_passwd)
smtp.sendmail(send_people,[recv_people,],msg.as_string())
smtp.quit()
#if __name__ == '__main__':
mail(sys.argv[1])
python发邮件以附件的方式
最新推荐文章于 2024-07-11 15:16:06 发布