使用C#和System.Net.Mail命名空间发送电子邮件时,可以在MailMessage对象上设置"发件人"和"发件人"属性,但这些都不允许您创建MAIL FROM和来自的地址进入DATA部分彼此不同.MAIL FROM设置为"From"属性值,如果设置"Sender",它只在DATA部分添加另一个头字段.这导致"来自X@Y.COM代表A@B.COM",这不是您想要的.我错过了什么吗?
用例是控制代表其他人发送的新闻稿等的NDR目的地.
我目前正在使用aspNetEmail而不是System.Net.Mail,因为它允许我正确地执行此操作(与大多数其他SMTP库一样).使用aspNetEmail,可以使用EmailMessage.ReversePath属性完成此操作.
MailMessage.Sender
将始终插入Sender
标题(代表您的电子邮件客户端解释).
如果您使用的是Network
交付方式SmtpClient
,.Sender
还会更改信封中的发件人.使用PickupDirectoryFromIis
传递方法将它留给IIS来确定信封发件人,IIS将使用From
地址,而不是Sender
地址.
你是这个意思吗?:
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("me@mycompany.com");
mail.To.Add("you@yourcompany.com");
//set the content
mail.Subject = "This is an email";
mail.Body = "this is a sample body with html in it. <b>This is bold</b> <font color=#336699>This is blue</font>";
mail.IsBodyHtml = true;
//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
Run Code Online (Sandbox Code Playgroud)
来自http://www.systemnetmail.com/faq/3.1.2.aspx