欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python3 發(fā)送任意文件郵件的實例

 更新時間:2018年01月23日 14:03:52   作者:zhishiqu  
下面小編就為大家分享一篇python3 發(fā)送任意文件郵件的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

實例如下所示:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import smtplib
import email.mime.multipart
import email.mime.text
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication

def send_email(smtpHost, sendAddr, password, recipientAddrs, subject='', content=''):
 msg = email.mime.multipart.MIMEMultipart()
 msg['from'] = sendAddr
 msg['to'] = recipientAddrs
 msg['subject'] = subject
 content = content
 txt = email.mime.text.MIMEText(content, 'plain', 'utf-8')
 msg.attach(txt)


 # 添加附件,傳送D:/mydev/yasuo.rar文件
 part = MIMEApplication(open('D:/mydev/6.rar','rb').read())
 part.add_header('Content-Disposition', 'attachment', filename="yasuo.rar")
 msg.attach(part)

 smtp = smtplib.SMTP()
 smtp.connect(smtpHost, '25')
 smtp.login(sendAddr, password)
 smtp.sendmail(sendAddr, recipientAddrs, str(msg))
 print("發(fā)送成功!")
 smtp.quit()

try:

subject = 'Python 測試郵件'
content = '這是一封來自 Python 編寫的測試郵件。'
send_email('smtp.163.com', '18310161797@163.com', '郵箱密碼', '526189064@qq.com', subject, content)
except Exception as err:
print(err)

以上這篇python3 發(fā)送任意文件郵件的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論