用户在我的ASP.NET App中注册后,我正在建立确认电子邮件流程。 这是我的代码:
var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code }));
SmtpClient smtpClient = new SmtpClient("smtp.office365.com", 25);
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = new System.Net.NetworkCredential(credentials, credentials);
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.Body = "Please confirm your account by clicking this link: <a href=\""
+ callbackUrl + "\">link</a>";
mail.From = new MailAddress(Address, App);
mail.To.Add(new MailAddress(user.Email));
//mail.CC.Add(new MailAddress("MyEmailID@gmail.com"));
smtpClient.Send(mail);
这是确认电子邮件:
[HttpGet]
[Route("ConfirmEmail", Name = "ConfirmEmailRoute")]
public async Task<IHttpActionResult> ConfirmEmail(string userId = "", string code = "")
{
//var _result = XElement.Parse(success).Value;
if (string.IsNullOrWhiteSpace(userId) || string.IsNullOrWhiteSpace(code))
{
ModelState.AddModelError("", "User Id and Code are required");
return BadRequest(ModelState);
}
IdentityResult result = await UserManager.ConfirmEmailAsync(userId, code);
if (result.Succeeded)
{
var response = new JObject();
response.Add(new JProperty("Email Verified", "You can now log in to the app."));
return Ok(response);
}
else
{
return GetErrorResult(result);
}
}
此电子邮件已通过桌面应用程序和手机上的Gmail应用程序成功发送。
对于苹果设备,邮件应用无法完全使用链接
即
callbackurl并非全部包含在链接中
谢谢。
答案 0 :(得分:0)
我只需要添加:
mail.IsBodyHtml = true;
链接已发送完毕。