Python发送邮件

2016/01/19 15:11
阅读数 92
  • 介绍
在玩树莓派的时候,希望能用Python来给自己发一份邮件。本文就是介绍如何使用Python来发送邮件的。 本文介绍了使用POP3来收取邮件,所以要能正确地收取邮件必须首先确保你的邮件服务器开启了POP3服务。
  • 发送简单邮件
[codesyntax lang="python"]
#!/usr/bin/evn python
#coding=utf-8

__author__ = 'surenpi'

import sys 
import time
import smtplib

def send_mail():
        try:
                handle = smtplib.SMTP('smtp.126.com', 25)
                handle.login('xxx%g@126.com', 'xxx')
                msg = 'To:xxx@qq.com\r\nFrom:xxx@126.com\r\nSubject:hello mail\r\npython mail test'
                handle.sendmail('xxx%g@126.com', 'xxx@qq.com', 'msg')
                handle.close()

                return 1
        except Exception,e:
                print e
                return 0
        pass

if __name__ == '__main__':
        send_mail()

        pass
[/codesyntax]
  • 参考
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
1
分享
返回顶部
顶部