Setting Return-Path with Python sendmail for a MIME message

前端 未结 1 1330
萌比男神i
萌比男神i 2021-01-13 22:11

Hi would like to set the \"Return-Path\" header for a MIME message I send with Python. Basically, I tried something like this :

message = MIMEMultipart()
mes         


        
1条回答
  •  悲哀的现实
    2021-01-13 22:27

    Return-Path is set by the SMTP protocol, it's not derived from the message itself. It'll be the Envelope From address is most setups.

    The proper way to accomplish this is:

    msg = email.message_from_string('\n'.join([
        'To: michael@mydomain.com',
        'From: michael@mydomain.com',
        'Subject: test email',
        '',
        'Just testing'
    ]))
    smtp = smtplib.SMTP()
    smtp.connect()
    smtp.sendmail('something@something.com', 'michael@mydomain.com', msg.as_string())
    

    0 讨论(0)
提交回复
热议问题