在电子邮件中创建将重定向到localhost的链接

时间:2016-09-01 00:09:00

标签: asp.net

我试图在我的电子邮件正文中创建一个链接,该链接将在asp.net中打开一个网页。 我知道这个网站还没有发布,因为它仍然在本地主机上运行,​​但是在我的visual studio运行时是否可以创建一个重定向到我的网页的链接?

这是我的代码:

 private void send_email()
    {
        MailMessage mm = new MailMessage();
        //The email that needs to be checked
        mm.To.Add(new MailAddress("******@gmail.com", "Email Check"));
        mm.From = new MailAddress("******@gmail.com");

        StringBuilder sb = new StringBuilder();

        sb.AppendFormat(@"
           <h3>We have reviews you transaction</h3>
            <br />
            <br />
            View our reply on Mej website
            <br />
            Enter your transaction code: 
            <br />
            <h2>" + "bla bla"
            + "</h2> Thank you!<br />"
            + "<small>To view your"
            +"transaction please proceed"
            + "<a href='~/Customers/new_web_page/quotation_01.aspx'runat='server'>here</a>"
            +"</small>");

        mm.Body = sb.ToString();
        mm.IsBodyHtml = true;
        mm.Subject = "Verification";
        SmtpClient smc1 = new SmtpClient();
        smc1.Host = "smtp.gmail.com";
        smc1.Port = 587;

        smc1.UseDefaultCredentials = false;

        smc1.Credentials = new NetworkCredential("*********@gmail.com", "*********");
        smc1.EnableSsl = true;
        smc1.Send(mm);
    }

每当我点击链接时,这是我的错误 enter image description here

1 个答案:

答案 0 :(得分:0)

StringBuilder sb = new StringBuilder();声明

之前添加此内容
var href = System.Web.VirtualPathUtility.ToAbsolute("~/Customers/new_web_page/quotation_01.aspx"); 

更改

"<a href='~/Customers/new_web_page/quotation_01.aspx'runat='server'>here</a>"

"<a href='" + href + "'>here</a>"