我正在尝试发送我的 GridView 中列出的所有电子邮件,但由于某种原因,电子邮件没有发送出去。我怀疑我的发送功能 (smtpClient.Send(mailMessage); 不工作或我遗漏了一些东西。请帮忙,因为我花了很多时间来解决这个问题。谢谢
protected void chkAll_CheckedChanged(object sender, EventArgs e)
{
foreach(GridViewRow gr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gr.FindControl("chkItem");
if(((CheckBox)sender).Checked)
cb.Checked = true;
else
cb.Checked = false;
}
}
protected void Button3_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
foreach(GridViewRow gr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gr.FindControl("chkItem");
if(cb.Checked)
{
sb.Append(GridView1.DataKeys[gr.RowIndex]["Email"].ToString());
sb.Append(",");
}
}
//Create instance of main mail message class.
System.Net.Mail.MailMessage mailMessage=new System.Net.Mail.MailMessage();
mailMessage.From = new System.Net.Mail.MailAddress(
System.Configuration.ConfigurationManager
.AppSettings["fromEmailAddress"]);
mailMessage.Priority = System.Net.Mail.MailPriority.High;
//Text/HTML
mailMessage.IsBodyHtml = false;
mailMessage.Body = "Hello, here is new email";
mailMessage.Subject = "RCA APPROVAL IS REQUIRED";
System.Net.Mail.SmtpClient smtpClient=new System.Net.Mail.SmtpClient();
try
{
smtpClient.Send(mailMessage);
Response.Write("<B>Email Has been sent successfully.</B>");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}