日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python附件发送到邮箱_python – 如何发送电子邮件附件?

發(fā)布時間:2025/3/15 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python附件发送到邮箱_python – 如何发送电子邮件附件? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

這是另一個:

import smtplib

from os.path import basename

from email.mime.application import MIMEApplication

from email.mime.multipart import MIMEMultipart

from email.mime.text import MIMEText

from email.utils import COMMASPACE, formatdate

def send_mail(send_from, send_to, subject, text, files=None,

server="127.0.0.1"):

assert isinstance(send_to, list)

msg = MIMEMultipart()

msg['From'] = send_from

msg['To'] = COMMASPACE.join(send_to)

msg['Date'] = formatdate(localtime=True)

msg['Subject'] = subject

msg.attach(MIMEText(text))

for f in files or []:

with open(f, "rb") as fil:

part = MIMEApplication(

fil.read(),

Name=basename(f)

)

# After the file is closed

part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)

msg.attach(part)

smtp = smtplib.SMTP(server)

smtp.sendmail(send_from, send_to, msg.as_string())

smtp.close()

它與第一個例子大致相同……但它應該更容易投入.

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的python附件发送到邮箱_python – 如何发送电子邮件附件?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。