基于C#的邮件群发如何实现?

li11131113 2006-12-18 09:51:28
同上,单邮件发送已会,如何实现邮件群发,是用for语句吗?
...全文
383 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyw84 2006-12-19
  • 打赏
  • 举报
回复
抄送
nimeide1234567890 2006-12-19
  • 打赏
  • 举报
回复
string nowDSN=ConfigurationSettings.AppSettings["data"];
SqlConnection myConnection=new SqlConnection(nowDSN);
SqlDataAdapter myCommand1=new SqlDataAdapter("select * from vendor order by vendor desc",myConnection);
DataSet ds1=new DataSet();
myCommand1.Fill(ds1, "vendor");
dr1 = ds1.Tables["vendor"].Rows[0];
int dscount=ds1.Tables["vendor"].Rows.Count;
//亞旭塑膠厂"楊莉"新采購單-----------------------------------------------------
for(int i1=0;i1<dscount;i1++)
{
SqlDataAdapter myCommand11=new SqlDataAdapter("select * from pur where (purchaser='楊莉' or purchaser='王慶媚') and status='0' and email_caption='0' and status3='1' and vendor='"+ds1.Tables["vendor"].Rows[i1]["vendor"].ToString()+"'",myConnection);
DataSet ds11=new DataSet();
myCommand11.Fill(ds11, "pur");
if(ds11.Tables["pur"].Rows.Count > 0)
{
dr11 = ds11.Tables["pur"].Rows[0];
int dscount11=ds11.Tables["pur"].Rows.Count;
for(int i11=0;i11<dscount11;i11++)
{
body1=body1+"<table border=1 bgcolor=e2f9ff><tr><td width=100>"+ds11.Tables["pur"].Rows[i11]["pono"].ToString()+"</td><td width=120>"+ds11.Tables["pur"].Rows[i11]["part"].ToString()+"</td><td width=350>"+ds11.Tables["pur"].Rows[i11]["specification"].ToString()+"</td><td width=100>"+ds11.Tables["pur"].Rows[i11]["precdate"].ToString()+"</td><td width=100>"+ds11.Tables["pur"].Rows[i11]["qty"].ToString()+"</td><td width=100>"+ds11.Tables["pur"].Rows[i11]["vendor"].ToString()+"</td></tr></table>"+"\r\n";
sum1=sum1+1;
sum11=sum11+1;
subject1=ds11.Tables["pur"].Rows[i11]["vendor"].ToString();
//-------------------------------------------------------------------
string CommandText;
SqlCommand myCommand111 = new SqlCommand();
myCommand111.Connection=myConnection;
myCommand111.Connection.Open();
myCommand111.CommandText = "update pur set email_caption='1' where p_id='"+ds11.Tables["pur"].Rows[i11]["p_id"].ToString()+"'";
myCommand111.ExecuteNonQuery();
myCommand111.Connection.Close(); //如果发送了一次,那么让字段email_caption变为1后就不会重复发送邮件
//-------------------------------------------------------------------
}

SmtpMail.SmtpServer="mail.lw-org.com";
MailMessage oMessage = new MailMessage();
oMessage.BodyFormat = MailFormat.Html;
oMessage.Priority = MailPriority.High;
oMessage.From = "jianfeng-luo@lw-org.com";
oMessage.To = ds1.Tables["vendor"].Rows[i1]["email"].ToString();
oMessage.Bcc = "li-yang@longwaycorp.com.cn;qingmei-wang@longwaycorp.com.cn";
//oMessage.Bcc = "jianfeng-luo@lw-org.com"+ds1.Tables["vendor"].Rows[i1]["email2"].ToString();
oMessage.BodyEncoding = Encoding.UTF8;
oMessage.Subject = "亞旭塑膠厂新采購單"+subject1;
oMessage.Body = "亞旭網路採購管理系統"+DateTime.Now.Date.ToShortDateString()+"傳送訊息如下:"+"\r\n"+sum1 +"條新單記錄"+"\r\n"+"<br><table border=1 bgcolor=718BD6><tr><td width=100>"+"采購單號"+"</td><td width=120>"+"料號"+"</td><td width=350>"+"料品名稱"+"</td><td width=100>"+"交貨日期"+"</td><td width=100>"+"數量"+"</td><td width=100>"+"供應商"+"</td></tr></table>"+body1;
SmtpMail.Send(oMessage);
Response.Write("OK!");
Response.Write("<font color='blue'>");
Response.Write(ds1.Tables["vendor"].Rows[i1]["vendor"].ToString());
Response.Write(ds1.Tables["vendor"].Rows[i1]["email"].ToString());
Response.Write(ds1.Tables["vendor"].Rows[i1]["ven_name"].ToString());
Response.Write("</font>");
Response.Write(sum1+"條記錄"+body1);
Response.Write("<br>");
}
body1="";
sum1=0;
}
Response.Write("<font color='red'>");
Response.Write("楊莉"+sum11);
Response.Write("條新單記錄");
Response.Write("</font>");
Response.Write("<br>");
dengenming 2006-12-18
  • 打赏
  • 举报
回复
可以把地址串提出来然后集体抄送

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧