Python 에서 메 일 을 보 내 고 베 끼 기

1516 단어 시스템 관련
전송:http://blog.51cto.com/lizhenliang/1875330
코드
#!/usr/bin/python
# -*- coding: utf-8 -*-
import smtplib

def sendMail(body):
    smtp_server = 'smtp.163.com'
    from_mail = '[email protected]'
    mail_pass = 'your_email_password'
    to_mail = ['[email protected]', '[email protected]']
    cc_mail = ['[email protected]']
    from_name = 'monitor' 
    subject = u'[    ][CW] xxx           ,      !'.encode('gbk')   #  gbk    ,           
#     msg = '''\
# From: %s 
# To: %s
# Subject: %s
# %s''' %(from_name, from_mail, to_mail_str, subject, body)  #               ,            ,   SMTP 554
    mail = [
        "From: %s " % (from_name, from_mail),
        "To: %s" % ','.join(to_mail),   #      ,       
        "Subject: %s" % subject,
        "Cc: %s" % ','.join(cc_mail),
        "",
        body
        ]
    msg = '
'.join(mail) # , join , , try: s = smtplib.SMTP() s.connect(smtp_server, '25') s.login(from_mail, mail_pass) s.sendmail(from_mail, to_mail+cc_mail, msg) s.quit() except smtplib.SMTPException as e: print "Error: %s" %e if __name__ == "__main__": sendMail("[Sending Reason] Aliyun had a list overflow event, please deal with it in time!

More Details: ......")

좋은 웹페이지 즐겨찾기