locked
How to resolve issues on SMTP mail send RRS feed

  • Question

  • User-218090889 posted

    I have this code to send email to user when user forget password, I am sending from my localhost pc. but the error I get says

    Server does not support secure connections.

    Now How do I resolve this so that it can work also on a Remote host?

    below is my code

     protected void eMailSubmit_Click(object sender, EventArgs e)
            {
                string username = "";
                string password = "";
                SqlConnection con = new SqlConnection(@"Data Source=My_DB;Integrated Security=False;");
                SqlCommand cmd = new SqlCommand("SubmitEmail", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Email", SqlDbType.NVarChar).Value = TextBoxSubmiteMail.Text;
                con.Open();
                SqlDataReader sdr = cmd.ExecuteReader();
                {
    
                    if (sdr.Read())
                    {
                        username = sdr["Email"].ToString();
                        password = sdr["Password"].ToString();                   
                    }
    
                }
                con.Close();
    
                if (username != TextBoxSubmiteMail.Text)
                {
                    lblemailSubmit.Text = "The submitted eMail does not belong to this account, check the eMail and try again";
                }
                else if (!string.IsNullOrEmpty(password)) {  
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress("myMail@gmail.com");  
                msg.To.Add(TextBoxSubmiteMail.Text);  
                msg.Subject = " Recover your Password";  
                msg.Body = ("Your Username is:" + username + "<br/><br/>" + "Your Password is:" + password);  
                msg.IsBodyHtml = true;  
      
                SmtpClient smt = new SmtpClient();  
                 
                smt.Send(msg);  
                lblemailSubmit.Text = "Username and Password Sent Successfully";
                lblemailSubmit.ForeColor = System.Drawing.Color.ForestGreen;  
            }  
        }   
            

    below is my configuration code:

    <configuration>
    <system.net>
            <mailSettings>
                <smtp deliveryMethod="Network">
                    <network host="smtp.gmail.com" 
                       port="25"   
                        enableSsl="true" 
                        defaultCredentials="false" 
                          userName="myMail@gmail.com" 
                          password="MyPassword" />
                </smtp>
            </mailSettings>
        </system.net>
    </configuration>

    Friday, August 11, 2017 12:59 AM

All replies