我设计了一个包含html页面作为邮件正文的邮件程序。 html页面中有某些链接。可以有任意数量的链接,我不知道它们。因为html页面中的所有内容均视为字符串。我想要的是每当我单击特定链接时,都应将该链接替换为指向中间页面的链接,在该页面中我希望通过查询字符串获取参数值。 这是我的代码-
protected void btnSubmit_Click(object sender, EventArgs e)
{
{
SendHTMLMail();
}
void SendHTMLMail()
{
StreamReader reader = new StreamReader(Server.MapPath("~/index1.html"));
string readFile = reader.ReadToEnd();
string myString = "http";
myString = readFile;
myString = myString.Replace(@"??", @"http://localhost:60488/url.aspx?" + "sender=" + Server.UrlEncode(this.txtUsername.Text) + "&reciever=" + Server.UrlEncode(this.txtTo.Text));
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress(txtUsername.Text);
Msg.To.Add(txtTo.Text);
Msg.Subject = txtSubject.Text;
Msg.Body = myString.ToString();
Msg.IsBodyHtml = true;
if (fuAttachment.HasFile)
{
string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
Msg.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
}
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(txtUsername.Text, txtpwd.Text);
smtp.EnableSsl = true;
smtp.Send(Msg);
Msg = null;
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
}
在此区块中-
StreamReader reader = new StreamReader(Server.MapPath("~/index1.html"));
string readFile = reader.ReadToEnd();
string myString = "http";
myString = readFile;
myString = myString.Replace(@"??", @"http://localhost:60488/url.aspx?" + "sender=" + Server.UrlEncode(this.txtUsername.Text) + "&reciever=" + Server.UrlEncode(this.txtTo.Text));
我尝试过的方法被认为是字符串形式的url,并赋予其初始值“ http”。由于http之后我什么都不知道,因为它可以是任何链接,例如-http://example.co.in或https://example.com 我想用中间页的链接替换该链接,也想知道http后的完整链接,并在查询字符串中发送该链接名称