在玩树莓派的时候,希望能用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]