发送电​​子邮件与多个MAILMESSAGE收件人 [英] Sending Email to multiple Recipients with MailMessage

查看:640
本文介绍了发送电​​子邮件与多个MAILMESSAGE收件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经存储在SQL Server多个电子邮件收件人。当我在网页上点击发送就应该发送电子邮件给所有recipients.I已经分居使用电子邮件;。



以下是单个收件人代码



 消息MAILMESSAGE新= MAILMESSAGE(); 
MailAddress fromMail =新的MailAddress(fromEmail);
Msg.From = fromMail;
Msg.To.Add(新MailAddress(toEmail));
如果(ccEmail =与&&安培;!bccEmail =!)
{
Msg.CC.Add(新MailAddress(ccEmail));
Msg.Bcc.Add(新MailAddress(bccEmail));
}
SmtpClient一个=新SmtpClient(SMTP服务器名称);
a.Send(MSG);
sreader.Dispose();


解决方案

轻松!



刚刚拆分输入的地址列表中的;性格,并把它们添加到邮件:

 的foreach(在addresses.Split VAR地址(新[] {; },StringSplitOptions.RemoveEmptyEntries))
{
mailMessage.To.Add(地址);
}

在这个例子中,地址包含 address1@example.com; address2@example.com


I have multiple email recipients stored in Sql Server. When I click send in the webpage it should send email to all recipients.I have separated emails using ';'.

Following is the single recipient code.

MailMessage Msg = new MailMessage();
MailAddress fromMail = new MailAddress(fromEmail);
Msg.From = fromMail;
Msg.To.Add(new MailAddress(toEmail));
if (ccEmail != "" && bccEmail != "")
{
    Msg.CC.Add(new MailAddress(ccEmail));
    Msg.Bcc.Add(new MailAddress(bccEmail));
}
SmtpClient a = new SmtpClient("smtp server name");
a.Send(Msg);
sreader.Dispose();

解决方案

Easy!

Just split the incoming address list on the ";" character, and add them to the mail message:

foreach (var address in addresses.Split(new [] {";"}, StringSplitOptions.RemoveEmptyEntries))
{
    mailMessage.To.Add(address);    
}

In this example, addresses contains "address1@example.com;address2@example.com".

这篇关于发送电​​子邮件与多个MAILMESSAGE收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆