Send to a recipient, while listing others in the sent-to list

梦想的初衷 提交于 2019-12-24 13:35:04

问题


I'd like to send an email to a single person, yet have the "sent to" list display a number of people. (I don't want those other people to receive the email).

A number of articles (here and here) suggest it's perfectly legal to specify different values for smtp address and mime addresses.

I'm using MailKit and this is what I have so far:

var message = new MimeMessage();
message.From.Add(new MailboxAddress("MeetingOfficeA", "noreply@office.com"));
message.To.Add(new MailboxAddress("Fidel Perez-Smith", "fidel@office.com"));

message.Headers.Add("To", "john.doe@office.com"); //this line actually sends the email to John Doe, which I don't want

message.Subject = "Testing";
message.Body = new TextPart ("plain") { Text = @"Testing 123" };

MailKit.Net.Smtp.SmtpClient client = new MailKit.Net.Smtp.SmtpClient();
client.Connect("smtpserver.office.com");
client.Send(message);

Is there something I can add so only Fidel receives the email, yet it looks like it was sent to multiple people?

(The question in link 1 is similar, but mainly discusses the 'from' addresses. I think my question should not be marked as duplicate because it relates to the 'to addresses' and will make it easier for other users to find. After all, it took a while to find that other link when I was researching my particular issue).


回答1:


The following code snippet will make it look like the message was sent to both Fidel Perez-Smith and John Doe, but in reality, it will only be sent to Fidel Perez-Smith:

var message = new MimeMessage ();
message.From.Add (new MailboxAddress ("MeetingOfficeA", "noreply@office.com"));
message.To.Add (new MailboxAddress ("Fidel Perez-Smith", "fidel@office.com"));
message.To.Add (new MailboxAddress ("John Doe", "john.doe@office.com");
message.Subject = "Testing";
message.Body = new TextPart ("plain") { Text = @"Testing 123" };

using (var client = new SmtpClient ()) {
    client.Connect ("smtpserver.office.com");
    client.Send (message, new MailboxAddress ("MeetingOfficeA", "noreply@office.com"), new [] { new MailboxAddress ("Fidel Perez-Smith", "fidel@office.com") });
    client.Disconnect (true);
}


来源:https://stackoverflow.com/questions/35321083/send-to-a-recipient-while-listing-others-in-the-sent-to-list

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