<p>When you send an email using C# and the System.Net.Mail namespace, you can set the "From" and "Sender" properties on the MailMessage object, but neither of these allows you to make the MAIL FROM and the from address that goes into the DATA section different from each other.  MAIL FROM gets set to the "From" property value, and if you set "Sender" it only adds another header field in the DATA section.  This results in "From X@Y.COM on behalf of A@B.COM", which is not what you want.  Am I missing something?</p>

<p>The use case is controlling the NDR destination for newsletters, etc., that are sent on behalf of someone else.</p>

<p>I am currently using <a href="http://www.aspnetemail.com/" rel="noreferrer">aspNetEmail</a> instead of System.Net.Mail, since it allows me to do this properly (like most other SMTP libraries).  With aspNetEmail, this is accomplished using the EmailMessage.ReversePath property.</p>

[{'answer_id': 51846, 'author': 'George Mauer', 'author_id': 5056, 'author_profile': 'https://Stackoverflow.com/users/5056', 'pm_score': 1, 'selected': False, 'text': '<p>Do you mean this?:</p>\n\n<pre><code>//create the mail message\n MailMessage mail = new MailMessage();\n\n //set the addresses\n mail.From = new MailAddress("me@mycompany.com");\n mail.To.Add("you@yourcompany.com");\n\n //set the content\n mail.Subject = "This is an email";\n mail.Body = "this is a sample body with html in it. &lt;b&gt;This is bold&lt;/b&gt; &lt;font color=#336699&gt;This is blue&lt;/font&gt;";\n mail.IsBodyHtml = true;\n\n //send the message\n SmtpClient smtp = new SmtpClient("127.0.0.1");\n smtp.Send(mail);\n</code></pre>\n\n<p>From <a href="http://www.systemnetmail.com/faq/3.1.2.aspx" rel="nofollow noreferrer">http://www.systemnetmail.com/faq/3.1.2.aspx</a></p>\n'}, {'answer_id': 387219, 'author': 'Romhein', 'author_id': 5818, 'author_profile': 'https://Stackoverflow.com/users/5818', 'pm_score': 2, 'selected': False, 'text': "<p>I just found how to do it:</p>\n\n<ul>\n<li>mail.From specify the email from visible to the final user</li>\n<li>mail.Sender specifies the envelope MAIL FROM</li>\n</ul>\n\n<p>That's it (even if it took me a while to figure it out)</p>\n"}, {'answer_id': 652464, 'author': 'bzlm', 'author_id': 7724, 'author_profile': 'https://Stackoverflow.com/users/7724', 'pm_score': 3, 'selected': False, 'text': '<p><code>MailMessage.Sender</code> will always insert a <code>Sender</code> header (interpreted as <em>on behalf of</em> in your e-mail client). </p>\n\n<p>If you use the <code>Network</code> delivery method on the <code>SmtpClient</code>, <code>.Sender</code> will also change the sender in the envelope. Using the <code>PickupDirectoryFromIis</code> delivery method will leave it to IIS to determine the envelope sender, and IIS will use the <code>From</code> address, not the <code>Sender</code> address. </p>\n\n<p><a href="http://social.msdn.microsoft.com/Forums/en-US/ncl/thread/a26c273a-18eb-4143-8631-233088977b21/" rel="noreferrer">There\'s a similar question on MSDN here.</a> </p>\n'}, {'answer_id': 39726489, 'author': 'Corben Leek', 'author_id': 1396350, 'author_profile': 'https://Stackoverflow.com/users/1396350', 'pm_score': 2, 'selected': False, 'text': '<p>If you add the following lines the Return-Path and the Reply-To headers are set in the mail header.</p>\n\n<pre><code>Dim strReplyTo As String = "email@domain.tld"\nmessage.ReplyToList.Add(strReplyTo)\nmessage.Headers.Add("Return-Path", strReplyTo)\n</code></pre>\n\n<p>And if you click on reply the e-mail set to the Reply-To address</p>\n'}]
['https://Stackoverflow.com/questions/51793', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1219/']