中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Python發(fā)郵件帶附件

2018-07-20    來源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬Linux鏡像隨意使用
import os
import sys
from smtplib import SMTP
from email.MIMEMultipart import MIMEMultipart
from email.mime.application import MIMEApplication
import time

def sendFildByMail(config):

    print 'Preparing...', 

    message = MIMEMultipart( ) 
    message['from'] = config['from'] 
    message['to'] = config['to'] 
    message['Reply-To'] = config['from'] 
    message['Subject'] = config['subject'] 
    message['Date'] = time.ctime(time.time()) 

    message['X-Priority'] =  '3' 
    message['X-MSMail-Priority'] =  'Normal' 
    message['X-Mailer'] =  'Microsoft Outlook Express 6.00.2900.2180' 
    message['X-MimeOLE'] =  'Produced By Microsoft MimeOLE V6.00.2900.2180' 

    #注意這一段
    f=open(config['file'], 'rb') 
    file = MIMEApplication(f.read())
    f.close()
    file.add_header('Content-Disposition', 'attachment', filename= os.path.basename(config['file'])) 
    message.attach(file) 

    print 'OK' 
    print 'Logging...', 

    smtp = SMTP(config['server'], config['port'])
    smtp.ehlo()
    smtp.starttls()
    smtp.ehlo()
    smtp.login(config['username'], config['password'])

    print 'OK'
    print 'Sending...',

    smtp.sendmail (config['from'], [config['from'], config['to']], message.as_string())

    print 'OK'

    smtp.close()

    time.sleep(1)

if __name__ == "__main__":
    if len(sys.argv) < 2: 
        print 'Usage: python %s <file path>' % os.path.basename(sys.argv[0]) 
        #sys.exit(-1) 
    else:
        #587,  25
        sendFildByMail({ 
            'from': "xxx@xxx.com",
            'to': 'xxx@xxx.com', 
            'subject': '[pysend]Send file %s' % sys.argv[1], 
            'file': sys.argv[1], 
            'server': 'smtp.xxx.com', 
            'port': 587,
            'username': 'username', 
            'password': 'password'})
    wait=raw_input("end.")

標(biāo)簽: isp

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:使用正則表達(dá)式來檢測(cè)標(biāo)簽是否關(guān)閉

下一篇:Python將byte數(shù)組轉(zhuǎn)換為int