码迷,mamicode.com
首页 > 编程语言 > 详细

Python发送邮件脚本

时间:2018-03-02 15:39:50      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:python

本脚本使用的163邮箱

此脚本需要进入163邮箱设置客户端授权密码:

技术分享图片

mail.py脚本源码:

#!/usr/bin/env python
#-*- coding: UTF-8 -*-
import os,sys
reload(sys)
sys.setdefaultencoding('utf8')
import getopt
import smtplib
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from  subprocess import *
def sendqqmail(username,password,mailfrom,mailto,subject,content):
    gserver = 'smtp.163.com'
    gport = 25
    try:
        msg = MIMEText(unicode(content).encode('utf-8'))
        msg['from'] = mailfrom
        msg['to'] = mailto
        msg['Reply-To'] = mailfrom
        msg['Subject'] = subject
        smtp = smtplib.SMTP(gserver, gport)
        smtp.set_debuglevel(0)
        smtp.ehlo()
        smtp.login(username,password)
        smtp.sendmail(mailfrom, mailto, msg.as_string())
        smtp.close()
    except Exception,err:
        print "Send mail failed. Error: %s" % err
def main():
    to=sys.argv[1]
    subject=sys.argv[2]
    content=sys.argv[3]
    sendqqmail('your_email@163.com','邮箱的授权码','your_email@163.com',to,subject,content)
if __name__ == "__main__":
    main()


Python发送邮件脚本

标签:python

原文地址:http://blog.51cto.com/11924224/2074822

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!