How to set the bounce address using System.Net.Mail?

自古美人都是妖i 提交于 2019-12-10 11:06:51

问题


I'm trying to implement the Variable envelope return path (VERP) method to manage email addresses (ie when an email I send bounces back I want it to be sent to a specific email address so that I can update my database to avoid sending emails to that email address in the future).

According to this article it is possible to specify the email address a bounce email is sent to. How do you do this in .Net?

For example say I (me@myserver.com) want to send an email to you (you@yourserver.com). If you@yourserver.com doesn't exist anymore I want yourserver to send the bounce email to bounce-you=yourserver.com@myserver.com). This way when I receive this bounced email I know that you@yourserver.com is not a valid email address anymore and I can update my database accordingly.

In this example, the bounce address would be: bounce-you=yourserver.com@myserver.com
How do you specify it using System.Net.Mail?


回答1:


The bottom line is that you cannot do this in .NET. You can only set the FROM address, which System.Net.Mail will also use as the Envelope-From.

To do something like this, you would need to use a 3rd party SMTP object like the one I wrote:

http://www.aspnetemail.com

In aspNetEmail, you can do something like:

EmailMessage msg = new EmailMessage();
msg.ReversePath = "bounceEmailAccountHere@whatever.com

aspNetEmail will use the ReversePath value in the MAIL FROM command during the SMTP Session. I could have easily of called this property "ReturnPath" or "EnvelopeFrom". In retrospect, EnvelopeFrom would have been a better name.



来源:https://stackoverflow.com/questions/2077135/how-to-set-the-bounce-address-using-system-net-mail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!