郵件群發界面如下:
protected void btn_send_Click(object sender, EventArgs e)
...{
MailMessage message = new MailMessage();
//獲取發送者地址
message.From = new MailAddress(tbx_address.Text.Trim());
//獲取主題
message.Subject = tbx_subject.Text.Trim();
//獲取發送郵件主題
message.Body = we_content.Text.Trim();
message.IsBodyHtml = true;
//設置數據庫鏈接
SqlConnection conn = new SqlConnection(getstring());
conn.Open();
//數據查詢用的是存儲過程
SqlCommand cmd = new SqlCommand("SelectEmail", conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter dutyparameter = cmd.Parameters.Add("@MemberDuty", SqlDbType.NVarChar, 20);
dutyparameter.Value = ddl_selectemail.SelectedValue;
SqlDataReader dr = cmd.ExecuteReader();
//執行查詢獲得要發往的郵件地址
while (dr.Read())
另外在web。config設置發送郵件的遠程服務器連接
代碼如下