问题
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