locked
How to get asp.net Email forgot password Authentication to work? RRS feed

  • Question

  • User2142845853 posted

    using VS2017 c# v4.6.1 ? in a web forms project (with MVC) trying to implement security and have to make the email the forgotten password link work;  I did in the past and created a custom gmail account and set that up in the web.config, 

    In the webforms I uncommented the forgot and reset password?  So in the login screen Forgot Password says it works but doesnt send anything. It validates the user is in the system (setup before this app), not sure how it verifies but in the IF block, it passes the test that the user is verified and goes to send the email but no emails are received. 

    so far just copied across the web.config of the gmail settings from a previous working project

    Friday, January 25, 2019 5:49 AM

Answers

  • User2142845853 posted

     public class EmailService : IIdentityMessageService
        {
            public Task SendAsync(IdentityMessage message)
            {
                // Plug in your email service here to send an email.
                return Task.FromResult(0);
            }
        }

    To send email you have to plug in the code that does the email

     public Task SendAsync(IdentityMessage message)
            {
                // Plug in your email service here to send an email.
                return configSendGridasync(message);
            }

    Then add the method

     private Task configSendGridasync(IdentityMessage message)
            {
    
                MailMessage mailMsg = new MailMessage();
    
                // To
                mailMsg.To.Add(new MailAddress(message.Destination.ToString(), "To Name"));
    

    It will need these namespaces

    using System.Net.Mail;
    using System.Net.Mime;

    more detail:  https://github.com/sendgrid/sendgrid-csharp/issues/315

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 25, 2019 4:35 PM