#!/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 = '[email protected]'
# recv_people = '[email protected]'
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发邮件以附件的方式
猜你喜欢
转载自blog.csdn.net/qq_37369726/article/details/109205844
今日推荐
周排行