我使用的是下面的code,而且只发送一个电子邮件 - 我要发送邮件到多个地址
。有关获得多个电子邮件使用:
字符串的ConnectionString = ConfigurationManager.ConnectionStrings [email_data]的ConnectionString。
OleDbConnection的con100 =新的OleDbConnection(的connectionString);
OleDbCommand的cmd100 =新的OleDbCommand(选择最前的bulk_tbl 3封电子邮件,con100);
OleDbDataAdapter的DA100 =新OleDbDataAdapter的(cmd100);
数据集DS100 =新的DataSet();
da100.Fill(DS100);
的for(int i = 0; I< ds100.Tables [0] .Rows.Count;我++)
//尝试
{
串all_emails = ds100.Tables [0] .Rows [I] [0]的ToString();
{
串allmail = all_emails +;;
Session.Add(ad_emails,allmail);
回复于(会话[ad_emails]);
发送邮件();
}
}
和发送我使用的电子邮件:
字符串SENDTO =会话[ad_emails]的ToString()。
MailMessage消息=新MailMessage(info@abc.com,SENDTO,主题,身体);
SmtpClient emailClient =新SmtpClient(mail.smtp.com);
System.Net.NetworkCredential SMTPUserInfo =新System.Net.NetworkCredential(ABC,ABC);
emailClient.UseDefaultCredentials = TRUE;
emailClient.Credentials = SMTPUserInfo;
emailClient.Send(消息);
解决方案
现在的问题是,你是提供用分号分隔的 MailMessage
构造函数的地址列表当只需要一个字符串,再presenting单个地址:
这包含了电子邮件的收件人。
的地址的字符串或者可能以逗号分隔的列表(见下文)。
来源
要指定多个地址,您需要使用To属性是一个MailAddressCollection,尽管这些页面上的例子没有表现得很清楚:
message.To.Add(one@example.com,two@example.com));
电子邮件地址添加到MailAddressCollection。多个电子邮件地址必须以逗号分隔()。
MSDN页面
因此创造了 MailMessage
与逗号的分隔列表应该工作。
I am using the below code, and it only sends one email - I have to send the email to multiple addresses.
For getting more than one email I use:
string connectionString = ConfigurationManager.ConnectionStrings["email_data"].ConnectionString;
OleDbConnection con100 = new OleDbConnection(connectionString);
OleDbCommand cmd100 = new OleDbCommand("select top 3 emails from bulk_tbl", con100);
OleDbDataAdapter da100 = new OleDbDataAdapter(cmd100);
DataSet ds100 = new DataSet();
da100.Fill(ds100);
for (int i = 0; i < ds100.Tables[0].Rows.Count; i++)
//try
{
string all_emails = ds100.Tables[0].Rows[i][0].ToString();
{
string allmail = all_emails + ";";
Session.Add("ad_emails",allmail);
Response.Write(Session["ad_emails"]);
send_mail();
}
}
and for sending the email I use:
string sendto = Session["ad_emails"].ToString();
MailMessage message = new MailMessage("info@abc.com", sendto, "subject", "body");
SmtpClient emailClient = new SmtpClient("mail.smtp.com");
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("abc", "abc");
emailClient.UseDefaultCredentials = true;
emailClient.Credentials = SMTPUserInfo;
emailClient.Send(message);
解决方案
The problem is that you are supplying a list of addresses separated by semi-colons to the MailMessage
constructor when it only takes a string representing a single address:
A String that contains the address of the recipient of the e-mail message.
or possibly a list separated by commas (see below).
Source
To specify multiple addresses you need to use the To
property which is a MailAddressCollection
, though the examples on these pages don't show it very clearly:
message.To.Add("one@example.com, two@example.com"));
The e-mail addresses to add to the MailAddressCollection. Multiple e-mail addresses must be separated with a comma character (",").
MSDN page
so creating the MailMessage
with a comma separated list should work.
相关推荐
最新文章