在电子邮件中发送链接

时间:2017-06-01 06:26:42

标签: c# asp.net email smtp

早上好,

我目前正在尝试在用户填写表单后发送电子邮件。该电子邮件包含指向激活页面的链接。我生成链接的代码如下:

mailMessage.Body = "<h1>Please click the link below to activate your account</h1><br /><a href = '" + HttpContext.Current.Request.Url.AbsoluteUri.Replace("Activation.aspx", "Activation.aspx?userId=" + userId) + "'>Click here to activate your account.</a>";

但是,发送时电子邮件显示的网址是:

http://localhost:52621/RegisterUser.aspx

我做错了什么?如生成链接的代码所示,我试图通过Activation.aspx的名称到达页面,这不会发生。任何建议都会很棒。提前谢谢。

1 个答案:

答案 0 :(得分:0)

您可能正在端口52621上运行本地开发服务器,这就是您获取上述URL的原因。

当您发布项目时,它看起来会有所不同,可能会在某些领域运行,例如

https://www.example.com/RegisterUser.aspx

如果您希望获得已发布状态的链接,则一种解决方案是手动编码:

mailMessage.Body = "<h1>Please click the link below to activate your account</h1><br /><a href='https://www.example.com/Activation.aspx?userId=" + userId + "'>Click here to activate your account.</a>";
但是,我不喜欢那个。

如果您的项目将发布到多个环境,您可以将其域写入web.config文件,具体取决于当前构建配置,如下所述:

Using different Web.config in development and production environment

相关问题