user20413691
user20413691

Reputation:

Sending URL Link to Email ASP.NET WEB API

I'm trying to generate a confirmation link to be sent to the email. The email was sent and received but the link is just not there. heres the code

[HttpPost]
        public async Task<IActionResult> SendEmail(Otp request)
        {

            randomcode = CreateRandomToken();
            var confirmationLink = Url.Action("confirmotp", "Authentication", new {randomcode}, Request.Scheme);
            var email = new MimeMessage();
            email.From.Add(MailboxAddress.Parse(_config.GetSection("EmailUsername").Value));
            email.To.Add(MailboxAddress.Parse(request.EmailAddress));
            email.Subject = "Confirmation Link For" + (request.EmailAddress);
            email.Body = new TextPart(TextFormat.Html)
            {
                Text = "Hello " + request.EmailAddress + ", click on the link: " + confirmationLink
            }
            using var smtp = new SmtpClient();
            smtp.Connect(_config.GetSection("EmailHost").Value, 587, SecureSocketOptions.StartTls);
            smtp.Authenticate(_config.GetSection("EmailUsername").Value, _config.GetSection("EmailPassword").Value);
            smtp.Send(email);
            smtp.Disconnect(true);
            return Ok();
        }

and this is the email I received :

Hello [email protected], click on the link:

the link is just not being read. appreciate any help i can get thank you.

Upvotes: 0

Views: 340

Answers (1)

Samir Kumar Dutta
Samir Kumar Dutta

Reputation: 9

Please try this to create the URL:

Uri uri = new Uri(url);

More details can be found in How to build a Url?

Upvotes: -1

Related Questions