I am using the following code to try to send an email asynchronously, but no email is sent and I am not sure what is being done incorrectly. I have also added the 2nd segment of code in the web.config for the emailing protocol.
SendEmailAsync code
await UserManager.SendEmailAsync(username.Id, "MTSS-B: Forgot Password", "Here is your new password. Please go back to the MTSS-B web tool and sign in. You will be prompted to create your own password.<br/><br/>" + tmpPass + "<br/><br/>MTSS-B Administrator");
Web.config code
<system.net> <mailSettings> <smtp> <network host="smtp1.airws.org" userName="" password="" /> </smtp> </mailSettings> </system.net>
****UPDATE****
I tested if an email could be sent with the usual method and an email was able to be sent using the following code.
MailMessage m = new MailMessage(new MailAddress(ConfigurationManager.AppSettings["SupportEmailAddr"]), new MailAddress(model.Email)); m.Subject = "MTSS-B: Forgot Password"; m.Body = string.Format("Here is your new password. Please go back to the MTSS-B web tool and sign in. You will be prompted to create your own password.<br/><br/>Password: " + tmpPass + "<br/><br/>MTSS-B Administrator"); m.IsBodyHtml = true; SmtpClient smtp = new SmtpClient("smtp2.airws.org"); smtp.Send(m);
In your app you probably have a file called IdentityConfig.cs
in the App_Start
folder. That file probably has something like this towards the top:
public class EmailService : IIdentityMessageService { public Task SendAsync(IdentityMessage message) { // Plug in your email service here to send an email. return Task.FromResult(0); } }
change it to:
public class EmailService : IIdentityMessageService { public Task SendAsync(IdentityMessage message) { SmtpClient client = new SmtpClient(); return client.SendMailAsync(ConfigurationManager.AppSettings["SupportEmailAddr"], message.Destination, message.Subject, message.Body); } }
Customizing the send code to your liking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With