我希望有人能在这个问题上帮助我。此电子邮件功能的目的是向其电子邮件在 GridView 中列出的个人发送电子邮件,并在电子邮件正文中附加特定的 URL 字符串。我能够从 GridView 发送多封电子邮件,并在电子邮件正文的 URL 中传递当前查询字符串。所以到这里一切都很好。我有一个无法解决的挑战。我还想在 URL 中包含 GridView 中相应的电子邮件 ID。这是我当前 URL 的样子: //MyHost/BCA/Users/QMR.aspx?Post_ID=303
如果我的 gridview 看起来像这样:
ID Name Email Post_ID
-------------------------------------------------------------------
32 Mike xx@hot.com 303
然后我想在我的 URL 中包含此电子邮件的相应 ID,如下所示,并能够将 URL 发送给该用户: //MyHost/BCA/Users/QMR.aspx?Post_ID=303&ID=32
谢谢
这是我的代码:
protected void btnSendEmail_Click(object sender, EventArgs e)
{
MailMessage mailMessage = new MailMessage();
foreach (GridViewRow gr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gr.FindControl("chkItem");
if (cb.Checked)
{
mailMessage.To.Add(new MailAddress(GridView1.DataKeys[gr.RowIndex]["Assigned_To"].ToString()));
mailMessage.From = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["fromEmailAddress"]);
mailMessage.Priority = System.Net.Mail.MailPriority.High;
//Text/HTML
mailMessage.IsBodyHtml = false;
string mySubURI= HttpContext.Current.Request.Url.AbsoluteUri.ToString().Replace("Test.aspx", "QMR.aspx");
mailMessage.Body = "Hello, Please see this link" + mySubURI;
mailMessage.Subject = "My Email Test";
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);
}
}