import smtplib #调用了现成的包
import string
import os,sys
class netUtil:
# sendMail(errorSubject,errorBody)
def sendMail(self,_mailsubject,_mailbody):
mailserver = 'smtp.126.com'
mailuser = 'hkebao'
mailpassword = '132113132'
mailfrom = 'hkebao@126.com'
mailto = ['aaaaa@aaa.com', 'aaaaa@aaa.com']
mailsubject = _mailsubject
mailbody = _mailbody
mailbody = string.join(('From: %s' % mailfrom,
'To: %s' % mailto,
'Subject: %s' % mailsubject,
'',
mailbody),'\r\n')
# send mail
try:
smtp = smtplib.SMTP()
# set debug level
smtp.set_debuglevel(0)
smtp.connect(mailserver)
smtp.login(mailuser, mailpassword)
smtp.sendmail(mailfrom,mailto,mailbody)
smtp.quit()
return True
except:
return False
如果想要调用的话就可以直接这样来写就可以了:
if __name__ == '__main__':
ob=netUtil()
ob.sendMail("hello", "Test is First")
以后我想:如果一旦有问题发生了的话就可以发送邮件的形式进行处理判断的哦!
阅读(1651) | 评论(3) | 转发(0) |