Attach a txt file in Python smtplib

前端 未结 3 777
无人共我
无人共我 2020-12-03 06:57

I am sending a plain text email as follows:

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def send_mess         


        
3条回答
  •  一向
    一向 (楼主)
    2020-12-03 07:27

    The same way, using msg.attach:

    from email.mime.text import MIMEText
    
    filename = "text.txt"
    f = file(filename)
    attachment = MIMEText(f.read())
    attachment.add_header('Content-Disposition', 'attachment', filename=filename)           
    msg.attach(attachment)
    

提交回复
热议问题