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!"
上一篇: HTTP报文格式
下一篇: HTTP报文格式详细讲解