|
代码如下:记录排错日志:
# !/usr/bin/env python
# -*- coding=utf-8 -*-
import smtplib
from email.mime.text import MIMEText
import sys
import logging
import time
sender = 'shiyiguo@yijiaoyuan.net'
smtp_server = 'smtp.exmail.qq.com'
username = sender[:]
password = 'Yjy@yunwei123'
log_format = time.strftime("%Y%m%d")
time_format = time.strftime("%Y-%m-%d %H:%M:%S")
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG, filename = '/tmp/smail' + log_format + '.log')
logging.info(time_format + ': starting sendmail record')
try:
receiver = sys.argv[1]
except Exception, e:
print e
finally:
logging.debug('receiver:\n\r\t' + receiver)
try:
subject = sys.argv[2]
except Exception, e:
print e
finally:
logging.debug('subject:\n\r\t' + subject)
try:
content = sys.argv[3]
except Exception, e:
print e
finally:
logging.debug('content:\n\r\t' + content)
msg = MIMEText(content, 'plain', 'utf-8')
smtp = smtplib.SMTP()
smtp.connect(smtp_server)
msg['Subject'] = subject
try:
smtp.login(username, password)
try:
print receiver,sender,subject,msg
smtp.sendmail(sender, receiver , msg.as_string())
except Exception, e:
print e
logging.debug(time_format + ":\t" + str(e))
except Exception, e:
print e
logging.info(time_format + '\terror message:\t' + str(e))
logging.debug("\rending logging record.......\r\n")
smtp.quit()
|
|
|