在Web API项目中的电子邮件中发送可点击的深层链接

时间:2019-01-26 17:03:30

标签: c# android asp.net-web-api2 deep-linking

我正在尝试调用将通过电子邮件发送给用户的深层链接。 这是一种典型的忘记密码的情况,但是用户无需通过Web链接重设密码,而是可以在android应用程序中进行设置。

这是我生成电子邮件的方式。

[HttpPost]   
[AllowAnonymous]
    [Route("ForgotPassword")]
    public async Task<IHttpActionResult> ForgotPassword(ForgotPasswordBindingModel model)
    {
        if (ModelState.IsValid)
        {
            var user = await AppUserManager.FindByEmailAsync(model.Email);
            if (user == null || !(await AppUserManager.IsEmailConfirmedAsync(user.Id)))
            {
                // Don't reveal that the user does not exist or is not confirmed
                return Ok();
            }

            // Send an email with this link
            string code = await AppUserManager.GeneratePasswordResetTokenAsync(user.Id);
            //var callbackUrl = new Uri(Url.Link("ResetPasswordRoute", new { user.Id, code }));
            var callbackIntent = "intent://forgotpassword?code="+code+"#Intent;scheme=challengehunt;package=com.seed.challengehunt;end";
            await AppUserManager.SendEmailAsync(user.Id, "Reset Password", "This would only work if you are seeing this email in an android device. Please reset your password by clicking <a href=\"" + callbackIntent + "\">here</a>");
            return Ok();
        }
        return BadRequest(ModelState);


    }

这是我附加到用户管理器的电子邮件服务

private async Task ConfigureGmailAsync(IdentityMessage message)
    {
        // Mail message
        var mail = new MailMessage()
        {
            From = new MailAddress("xyz@xyz.com", "Admin"),
            Subject = message.Subject,
            Body = message.Body,
            IsBodyHtml=true
        };

        // Credentials
        var credentials = new NetworkCredential("admin@xyz.com", "xyz");


        mail.To.Add(message.Destination);


        // Smtp client
        var client = new SmtpClient()
        {
            Port = 8889,
            UseDefaultCredentials = false,
            Host = "mail.domain.com",
            EnableSsl = false,
            Credentials = credentials
        };

        // Send it...         
        await client.SendMailAsync(mail);
    }

这是我收到的电子邮件enter image description here

如您所见,该链接不可点击。

有任何提示吗?

0 个答案:

没有答案