2010-07-08 115 views
1

可能重複:
Sending an email to multiple addresses/recipients多郵件發送

我使用下面的代碼,而且只發送一個郵件 - 我要發送多封電子郵件。

爲了得到一個以上的電子郵件,我使用:

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(); 
       } 
      } 
     } 
    } 

,併發送一個電子郵件我用

string sendto = Session["ad_emails"].ToString(); 

    MailMessage message = new MailMessage("[email protected]", 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); 

回答

0

嘗試把代碼發送部分在一個循環。下面一行:

emailClient.Send(message); 

只發送一個電子郵件,例如。