欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python模块: smtplib

程序员文章站 2022-07-10 15:25:32
...
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import smtplib
#from email.mime.Text import MIMEText  
from email.MIMEText import MIMEText
from email.Header import Header

sender = '[email protected]'
receivers = ['[email protected]','[email protected]']
smtpserver = 'smtp.mxhichina.com'
username = '[email protected]'
password = 'baicells_root'
from_text = 'baicells'
to_text = '¶­·å,À'
#date = os.popen('date +%Y%m%d').read()
date_all = os.popen("date +'%Y-%m-%d %H:%M:%S'").read()
subject =  '¸£ÖÝeGWÁ÷Á¿Í³¼Æ'+date_all
mytext = os.popen('python dailystatic.py `date +%Y%m%d`').read()
#print date
#print date_all
print subject
print mytext

msg = MIMEText(mytext, 'plain', 'utf-8')#ÖÐÎÄÐè²ÎÊý¡®utf-8¡¯£¬µ¥×Ö½Ú×Ö·û²»ÐèÒª  
msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = Header(from_text, 'utf-8')
msg['To'] = Header(to_text, 'utf-8')


try:
        smtp = smtplib.SMTP()
        smtp.connect('smtp.aliyun.com')
        smtp.login(username, password)
        smtp.sendmail(sender, receivers, msg.as_string())
        smtp.quit()
        print "success!"

except smtplib.SMTPException:
        print "error!"