python 发邮箱

import smtplib
from smtplib import SMTP_SSL
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header

host_server="smtp.sina.com"
sender_sina="[email protected]"
pwd="xxxxx"
sender_sina_mail="[email protected]"#发件人邮箱
receiver="[email protected]"

mail_title="基金"
mali_content="哈哈哈哈"

msg=MIMEMultipart()#邮件主体
msg["Subject"]=Header(mail_title,'utf-8')
msg["From"]=sender_sina_mail
msg["To"]=Header("测试邮件","utf-8")
msg.attach(MIMEText(mali_content,"plain","utf-8"))#邮件正文

smtp=SMTP_SSL(host_server)#ssl登入
smtp.login(sender_sina,pwd)
smtp.sendmail(sender_sina_mail,receiver,msg.as_string())
smtp.quit()


你可能感兴趣的:(python)