开发者

Sending file attachments using SMTPLIB.data()

开发者 https://www.devze.com 2023-02-07 10:34 出处:网络
I\'m trying to send an email using smtplib using the low-level commands such as MAIL, RCPT and DATA. This allows me to disguise the To field while still delivering to the proper inbox (required). My

I'm trying to send an email using smtplib using the low-level commands such as MAIL, RCPT and DATA.

This allows me to disguise the To field while still delivering to the proper inbox (required). My issue is that I have not foun开发者_如何学Cd a way to send file attachments this way, and I have not found a way to 'spoof' the To field when using smtp_server.sendmail(). Here's the 'raw' method:

    smtp_server = smtplib.SMTP('smtp.mail.server.com', 587)
    smtp_server.ehlo()
    smtp_server.starttls()
    smtp_server.ehlo()
    smtp_server.login('user','pass')

    smtp_server.mail(sender)
    smtp_server.rcpt(inbox)
    data = """From: {0}
To: {1}

{2}"""
    data = data.format(sender, recipient, message)
    smtp_server.data(data)
    smtp_server.close()

Thanks for any assistance.


This was actually pretty simple, create the MIMEMultipart message object, and simply call

smtp_server.data(message.as_string())
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号