Question

What im trying to do is to set up smail mail server with lamson (lamsonproject.org). Its working very well, but i have problem with setting return path and for that reason, bounces are going to 'From' address and therefore not reaching my mail server.

Lamson uses pythons smtplib to send mails out.

The "talk" between my project and my smtp server goes like that:

send: 'ehlo xxx.mydomiain.com\r\n'
reply: '250-smtp.smtpserver.com\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-SIZE 20000000\r\n'
reply: '250-VRFY\r\n'
reply: '250-ETRN\r\n'
reply: '250-STARTTLS\r\n'
reply: '250-XVERP\r\n'
reply: '250 8BITMIME\r\n'
reply: retcode (250); Msg: smtp.smtpserver.com
PIPELINING
SIZE 20000000
VRFY
ETRN
STARTTLS
XVERP
8BITMIME
send: u'mail FROM:<me@myotherdomain.com> size=352\r\n'
reply: '250 Ok\r\n'
reply: retcode (250); Msg: Ok
send: u'rcpt TO:<pleasebouncethis@myotherdomain.com>\r\n'
reply: '250 Ok\r\n'
reply: retcode (250); Msg: Ok
send: 'data\r\n'
reply: '354 End data with <CR><LF>.<CR><LF>\r\n'
reply: retcode (354); Msg: End data with <CR><LF>.<CR><LF>
data: (354, 'End data with <CR><LF>.<CR><LF>')
send: 'MIME-Version: 1.0\r\nTo: pleasebouncethis@myotherdomain.com\r\nSubject: Testing bounces\r\nSender: MAILER-DAEMON@mydomiain.com\r\nReturn-Path: MAILER-DAEMON@mydomain.com\r\nReply-To: MAILER-DAEMON@mydomain.com\r\nMessage-Id: 377b8dcdf661810d3dc73a4a01fe23b3\r\nFrom: me@myotherdomain.com\r\nContent-Type: text/plain; charset="utf-8"\r\nContent-Transfer-Encoding: base64\r\n\r\nc2RmZ2TDpGfDpGRsZsOkZ2xkZmc=\r\n.\r\n'
reply: '250 Ok: queued as E635D157D3\r\n'
reply: retcode (250); Msg: Ok: queued as E635D157D3
data: (250, 'Ok: queued as E635D157D3')
send: 'quit\r\n'
reply: '221 Bye\r\n'
reply: retcode (221); Msg: Bye
Done

so i can see, that the Return-Path is indeed in headers.

While looking for an answer i found this : Setting Return-Path with Python sendmail for a MIME message

Last comment in the answer is: Errors/bounces/etc. should go to the Envelope sender, not the address in From:.

When looking up Envelope sender and how to specify, i came across this wiki article: http://en.wikipedia.org/wiki/Bounce_address

This lists another possible header parameters like: return path, reverse path, envelope from, envelope sender, MAIL FROM, 2821-FROM, return address, From_, Errors-to.

I put all those into mail headers and - Voila - It worked.

My question is now - Do i really have to ALWAYS list so many possible options for return path in mail headers? Have the mail servers been configured to accept one or two of those parameters now? Are there better ways to make sure, that mail is returned to my mail server, when it bounces?

Alan.

Was it helpful?

Solution

If you are sending mail then you don't need to set any of those headers; the correct place for the envelope sender is in the MAIL FROM: command, so in your case:

MAIL FROM:<MAILER-DAEMON@mydomain.com>

Since this command is part of the SMTP protocol rather than the message itself, the recipient mail server adds a Return-Path header for the benefit of filters or other downstream processing where the original SMTP envelope is unavailable. See RFC2821:

When the delivery SMTP server makes the "final delivery" of a message, it inserts a return-path line at the beginning of the mail data. This use of return-path is required; mail systems MUST support it. The return-path line preserves the information in the <reverse-path> from the MAIL command.

OTHER TIPS

The from_addr you use in the sendmail(from_addr, to_addrs, msg, mail_options=[], rcpt_options=[]) function will be the one the one that get's set as the Return-Path.

The msg you send with the function can contain a different From: header that's the normal from address people will see when they open the email.

You can see this in the smtplib documentation. Quoting the note there:

The from_addr and to_addrs parameters are used to construct the message envelope used by the transport agents. sendmail does not modify the message headers in any way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top