如何在asp.net C#中从数据库向多个收件人发送电子邮件# [英] how to send email to multiple recipients from the DB in asp.net C#
本文介绍了如何在asp.net C#中从数据库向多个收件人发送电子邮件#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
client.Send(message);
public string SndUpdateNotificationEmail(string updateID, string Duedate)
{
// updateID = UpdateUserID(updateID);// where(Update_UserID = '" + updateID + "')
string sql = "select * from Cwipuser.CWIP_Variances";
SqlCommand cmd = new SqlCommand(sql, MyCon);
MyCon.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
if (!rdr.IsDBNull(1))
{
updateID = rdr.GetString(1);
}
MailMessage message = new MailMessage();
string MessageFrom = "SSCReportAndAnalysis@telkom.co.za";
message.From = new MailAddress(MessageFrom);
string MessageTo = updateID + "@telkom.co.za";
message.To.Add(MessageTo);
try
{
client.Dispose();
}
catch
{
//AlertString.Alert(ref _page, "Mail not sent", "key");
}
}
MyCon.Close();
return updateID;
}
推荐答案
http://www.c-sharpcorner.com/UploadFile/0c1bb2/sending-email-to-multiple-recipeint-using-Asp-Net/ [ ^ ]
在while循环之前创建邮件消息。
在循环内添加To或CC或BCC集合,如这个:
Create your mail message before while loop.
Within the loop add to To or CC or BCC collections like this:
MailMessage message = new MailMessage();
string MessageFrom = "SSCReportAndAnalysis@telkom.co.za";
message.From = new MailAddress(MessageFrom);
string MessageTo = string.empty;
while (rdr.Read())
{
if (!rdr.IsDBNull(1))
{
updateID = rdr.GetString(1);
message.To.Add(new MailAddresss(updateID + "@telkom.co.za"));
/*
the above line can be
message.CC.Add(new MailAddresss(updateID + "@telkom.co.za"));
OR
message.BCC.Add(new MailAddresss(updateID + "@telkom.co.za"));
*/
}
这篇关于如何在asp.net C#中从数据库向多个收件人发送电子邮件#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文