Sadeq Hatami Sadeq Hatami - 2 months ago 24
ASP.NET (C#) Question

PasswordRecovery control in asp.net



I created my web application and user

PasswordRecovery
Control.
My code in html :

<asp:PasswordRecovery ID="PasswordRecovery1" runat="server">
<MailDefinition From="mail@gmail.com" Subject="ResetPassword"
Priority="High"/>
</asp:PasswordRecovery>


And my web.config code is:

<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="mail@gmail.com">
<network
host="smtp.gmail.com"
port="25"
password="xxxxxxx"
defaultCredentials="true"/>
</smtp>
</mailSettings>
</system.net>


But I get these errors and it doesn't work.


1-The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

2-A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 173.194.66.109:25





my web.config code is

<configuration>
<system.web>
<roleManager enabled="true" />
<authentication mode="Forms" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>

<!-- ... -->

<system.net>
<mailSettings>
<smtp from="mail@gmail.com">
<network host="smtp.gmail.com" password="mypassword"
enableSsl="true" port="578" userName="hsadeghi.t@gmail.com" />
</smtp>
</mailSettings>
</system.net>
</configuration>


and form :

<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/master-store.Master"
AutoEventWireup="true" CodeBehind="UserPasswordRecovery.aspx.cs"
Inherits="Store.Pages.userpasswordrecovery" %>

<!-- ... -->
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="wrapper">
<div class="wrapper-rim">
<div class="site-content">
<div class="recovery-password" dir="rtl">
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server"/>
</div>
</div>
</div>
</div>
</asp:Content>

Answer

Aside from enabling ssl in your configuration, you also need to set the correct port, which is not 25. It's 587.

<smtp deliveryMethod="Network" from="someaccount@gmail.com">
   <network
      host="smtp.gmail.com"
      port="587"  
      enableSsl="true"
      userName="someaccount@gmail.com"
      password="somepassword"
      defaultCredentials="false"/>
</smtp>