如何在电子邮件中放置链接

时间:2017-12-21 14:29:07

标签: c#

当我向用户发送忘记密码邮件以重置他们的密码时,我的邮件&链接是这样的:

<br><br>You have forgotten your password so here is a link to reset it:<br>
www.bla.com/test/ResetPasswordVertification?VertificationCode=ojlqidsgkxERoPy6vCQHZtJ9jLRaYA

但是我想要这样的事情:你忘记了密码Click here来重置它

我试图添加<a> - 标记:

.Send("Reset Password ", "You have forgotten your password\n so here is link to reset it \n <a href=\"www.bla.dk/Account/loginResetPasswordVertification?VertificationCode=\">Click her</a>" 
    + user.VertificationCode 
    + "\n <br/> Best Regards \n ", 
    Email);
<br>

但我的结果是这样的:

  

您忘记了密码点击此处= asdawdasdawdadw

守则:

new MailHandler().Send("Reset Password", "You have forgotten your password \n so here is a link to reset it \n www.bla.com/test/ResetPasswordVertification?VertificationCode=" + user.VertificationCode, Email);

3 个答案:

答案 0 :(得分:2)

如果你想发送基于html的电子邮件而不是你必须这样做

string href = String.Format(@"www.bla.com/test/ResetPasswordVertification?VertificationCode={0}", user.VertificationCode);
msg = new MailMessage("xxxx@gmail.com",
                "yyyy@gmail.com", "Message from PSSP System",
                "You have forgotten your password<br/> "+
                "so here is link to reset it<br/>" +
                "<a href='"+ href +"'>click here !</a>");

msg.IsBodyHtml = true;

您需要设置标记IsBodyHtml

答案 1 :(得分:0)

在用户验证码后添加结束引号和</a>标记。

答案 2 :(得分:0)

.Send("Reset Password ", $"You have forgotten your password\n so here is link to reset it \n <a href=\"www.bla.dk/Account/loginResetPasswordVertification?VertificationCode=\{user.VertificationCode}">Click here</a>" + "\n <br/> Best Regards \n ", Email); <br>