Setting return path with Python sendmail for MIME message

Hi, I want to set the "Return-Path" header for the MIME message I am sending using Python. Basically, I tried something like this:

message = MIMEMultipart()
message.add_header("Return-Path", "something@something.com")
#...

smtplib.SMTP().sendmail(from, to, message.as_string())

The message I receive has a Return-Path header set to the same content as From, even if I explicitly add a Return-Path header.

How can I set the "Return-Path" header for a MIME message sent via smtplib sendmail in Python?

Thanks in advance.

+3
source share
1 answer

Return-Path SMTP, . .

:

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())
+2

Source: https://habr.com/ru/post/1756602/


All Articles