C#的邮件群发

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/>");

转载于:https://www.cnblogs.com/ymyglhb/archive/2008/08/08/1263525.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值