Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26253466
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: Python/Ruby

2009-01-20 18:23:34

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")
以后我想:如果一旦有问题发生了的话就可以发送邮件的形式进行处理判断的哦!

阅读(1608) | 评论(3) | 转发(0) |
0

上一篇:人生哲理

下一篇:python中正则表达式

给主人留下些什么吧!~~

chinaunix网友2009-03-05 12:03:24

不会的。在本机虚拟机上面测试正常的

chinaunix网友2009-03-05 09:31:52

更加奇怪的是为什么我在Linux环境中不能发送出去呢?难道有端口被 关闭了吗?

chinaunix网友2009-03-05 08:22:56

只能是在命令行中直接python运行的。不能直接在MyEclipse中运行的!