简体   繁体   English

.NET中的MailAddress

[英]MailAddress in .NET

I'm attempting to send an email and instead of sending 5 individual emails to each person, I would like to send one mass email to all 5 people. 我尝试发送一封电子邮件,而不是向每个人发送5封单独的电子邮件,而是向所有5个人发送一封批量电子邮件。 The difference here is that I want everyone to show up in the "TO" or "CC" lines. 此处的区别在于,我希望每个人都出现在“ TO”或“ CC”行中。 How can I do this? 我怎样才能做到这一点?

This will send only one message: 这只会发送一条消息:

MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("jdoe1@example.com", "Optional Name"));
msg.To.Add(new MailAddress("jdoe2@example.com"));
msg.To.Add(new MailAddress("jdoe3@example.com"));
msg.CC.Add(new MailAddress("jdoe4@example.com"));
msg.CC.Add(new MailAddress("jdoe5@example.com"));

// can add to BCC too
// msg.Bcc.Add(new MailAddress("jdoe5@example.com"));

msg.Body = "...";
msg.Subject = "...";

SmtpClient smtp = new SmtpClient();
smtp.Send(msg);
using System.Net.Mail;

...

MailMessage mmsg = new MailMessage();
mmsg.To.Add(new MailAddress("joe@user.com"));
mmsg.To.Add(new MailAddress("fred@user.com"));
mmsg.To.Add(new MailAddress("bob@user.com"));

// set other properties here...

SmtpClient client = new SmtpClient("mymailserver.com");
client.Send(mmsg);

Edit: aww, john's fingers are faster than mine ;) 编辑:aww,约翰的手指比我的快;)

MailMessage.CC.Add(new MailAddress(address)) MailMessage.CC.Add(新的MailAddress(地址))

Check out: http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.cc.aspx 检出: http : //msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.cc.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Net.Mail.MailAddress使用一个参数发送到多封电子邮件 - System.Net.Mail.MailAddress send to multiple emails with one parameter System.Net.Mail.MailAddress'解析器接受的格式是什么? - What is the format accepted by System.Net.Mail.MailAddress' parser? 我应该在域模型中使用System.Net.Mail.MailAddress还是仅使用字符串? - Should I use System.Net.Mail.MailAddress in my domain model, or just strings? 为什么 System.Net.Mail.MailAddress 构造函数在域部分解析带有斜杠“/”的电子邮件? - Why System.Net.Mail.MailAddress constructor parses email with slash "/" in domain part? 从用户输入文本中提取(多个)电子邮件到MailAddress格式(.NET) - Extract (multiple) emails from user-input text into the MailAddress format (.NET) MailAddress 构造函数中的多个地址 - Multiple address in MailAddress constructor 包含无效电子邮件的MailAddress - MailAddress with invalid email MailAddress:在邮件头中找到无效字符 - MailAddress: An invalid character was found in the mail header 如何获取Outlook.MeetingItem的发件人ExchangeUser和邮件地址 - How to get sender ExchangeUser and mailaddress for Outlook.MeetingItem 使用存储的变量而不是参数字符串创建MailAddress的新实例 - Create new instance of MailAddress using stored variables instead of strings for parameters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM