我希望有人可以帮我解决这个问题。此电子邮件功能的目的是向其电子邮件列在GridView中并在电子邮件正文中附加特定URL字符串的个人发送电子邮件。我能够从GridView发送多封电子邮件,并在Email主体的URL中传递当前查询字符串。所以一切都在这里工作正常。我有一个无法解决的挑战。我想在URL中包含GridView中相应的电子邮件ID。以下是我当前网址的外观: //MyHost/BCA/Users/QMR.aspx?Post_ID=303
如果我的gridview看起来像这样:
ID Name Email Post_ID
-------------------------------------------------------------------
32 Mike xx@hot.com 303
然后我想在我的网址中包含此电子邮件的相应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);
}
}
答案 0 :(得分:1)
试试这个
mySubURI += String.Format("&ID={0}", gr.Cells[0].Text);
通过它,您可以访问gridview中每行的第一列(即ID),并将其附加到现有Url的末尾
实际上我认为这是你需要Url的行,如果错了,那么请在你的问题中明确你需要帮助的地方
string mySubURI= HttpContext.Current.Request.Url.AbsoluteUri.ToString().Replace("Test.aspx", "QMR.aspx");
mySubURI += String.Format("&ID={0}", gr.Cells[0].Text);
mailMessage.Body = "Hello, Please see this link " + mySubURI;