邮件发送Python脚本

邮件发送Python脚本

#!/usr/bin/env python2

#-*- coding: utf-8 -*-
#导入smtplib,sys
import   smtplib,sys
from   email.mime.text  import   MIMEText
def   send_mail(sub,content):
#要发给谁,这里发给1个人
         mailto_list = [ "[email protected]" "[email protected]" ]
#设置服务器用户名、口令以及邮箱后缀
         mail_host = "smtp.163.com"
         mail_user = "whistle_tac"
         mail_pass = "1501019676"
         mail_postfix = "163.com"
         me = mail_user + "<" + mail_user + "@" + mail_postfix + ">"
         msg = MIMEText(content,_charset = 'utf-8' )
         msg[ 'Subject' =   sub
         msg[ 'From' =   me
         msg[ 'To' =   ";" .join(mailto_list)
         try :
                 =   smtplib.SMTP()
                 s.connect(mail_host)
                 s.login(mail_user,mail_pass)
                 s.sendmail(me, mailto_list, msg.as_string())
                 s.close()
                 return   True
         except   Exception, e:
                 print   str (e)
                 return   False
if   __name__  = =   '__main__' :
         if   send_mail( '这是python测试邮件' , 'python发送邮件' ):
                 print   '发送成功'
         else :
                 print   '发送失败'


你可能感兴趣的:(python,脚本,邮件发送)