標籤:python
本指令碼使用的163郵箱:
此指令碼需要進入163郵箱設定用戶端授權密碼:
mail.py指令碼源碼:
#!/usr/bin/env python#-*- coding: UTF-8 -*-import os,sysreload(sys)sys.setdefaultencoding('utf8')import getoptimport smtplibfrom email.MIMEText import MIMETextfrom email.MIMEMultipart import MIMEMultipartfrom 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" % errdef main(): to=sys.argv[1] subject=sys.argv[2] content=sys.argv[3] sendqqmail('[email protected]','郵箱的授權碼','[email protected]',to,subject,content)if __name__ == "__main__": main()
Python發送郵件指令碼