Thursday 24 November 2011

Password recovery with .NET using C#

I have this website with a login and a password recovery link. When I click the "forgot my password" link it takes me to a page which asks for username and security question answer. When I fill it out and hit submit. I am taken to a page that tells me the email was sent successfully but when I check my email, there is nothing there.
I'm hoping someone can tell me why I am not getting the password send to me. Here is my code.


  1. <%@ Page Language="C#" MasterPageFile="~/BlogMasterPage.master" %>
  2. <%@ Import Namespace="System.Net.Mail" %>
  3.  
  4. <script runat="server">
  5. protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
  6. {
  7. MailMessage msg = new MailMessage();
  8. msg.From = new MailAddress("xxxxxxxxxx@gmail.com", "name");
  9. msg.To.Add(new MailAddress("xxxxxxxxx@hotmail.com", "name"));
  10. msg.Subject = "Test Mail";
  11. msg.Body = "It's another test, yet again!";
  12. msg.IsBodyHtml = false;
  13. msg.Priority = MailPriority.High;
  14.  
  15. SmtpClient smtpClient = new SmtpClient();
  16. smtpClient.EnableSsl = true;
  17.  
  18. smtpClient.Send(e.Message);
  19. e.Cancel = true;
  20. }
  21.  
  22. </script>
  23.  
  24. <asp:Content ID="Content1" ContentPlaceHolderID="BlogMasterPage" runat="server">
  25. <br />
  26. <asp:PasswordRecovery ID="PasswordRecovery1" runat="server" OnSendingMail="PasswordRecovery1_SendingMail">
  27. <MailDefinition
  28. BodyFileName=""
  29. From="xxxxxxxxxxx@gmail.com"
  30. Subject="Password Recovery">
  31. </MailDefinition>
  32.  
  33. </asp:PasswordRecovery>
  34. <br />
  35. </asp:Content>
  36.  
  37.  
  38. <system.net>
  39. <mailSettings>
  40. <smtp from="xxxxxxxxxxxxx@gmail.com">
  41. <network host="smtp.gmail.com" password="xxxxxxx" userName="xxxxxxxxxxxxx@gmail.com" />
  42. </smtp>
  43. </mailSettings>
  44. </system.net>

No comments:

Post a Comment