1
votes

the eror:

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at forgot.Button1_Click(Object sender, EventArgs e) in c:\Users\Champion\Desktop\DinoSite\forgot.aspx.cs:line 24

the c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

public partial class forgot : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            using (var client = new SmtpClient())
            {
                MailMessage mail = new MailMessage("ozcohen06@gmail.com", (string)Email.Text);
                mail.Subject = "this is a test email.";
                mail.Body = "this is my test email body";
                client.Send(mail);
            }
            lblError.Text = "Message sent!";
        }
        catch (Exception ex)
        {
            lblError.Text = ex.ToString();
        }
    }
}

at the Web config:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5.2" />
  </system.web>
  <system.net>
    <mailSettings>
        <smtp deliveryMethod="Network" from="ozcohen06@gmail.com">
                <network host="smtp.gmail.com" userName="ozcohen06" password="mypass" port="587" enableSsl="true" />
        </smtp>
    </mailSettings>
</system.net>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  </system.serviceModel>
</configuration>
2
Try a different provider other than gmailNineBerry
Does it work if you change port to 465 (smtps)?Mattias Åslund
Add : smtp.UseDefaultCredentials = false; Most corporate networks will block ports like 465. Turning network credentials off will connect to your mail server without using smtp on the local network. You are connecting to gmail account which is web based. Network credentials are required only if you have a outlook account on the network which uses a proxy server to make connection to the outlook server.With the proxy server port forwarding is used to get through the firewalls that block port 465. Net 3.5 defaulted to credentials off, Net 4.0 default to on which msdn said was a security fix.jdweng
where to add this?Oz Cohen

2 Answers

0
votes

→ Use SMTP secured port: 465

→ Force your script to make SMTP authentication:

mail.UseDefaultCredentials = false;
mail.Credentials = basicCredential;
1
votes

Points to taken into consideration :

1) Access for less secure apps is "turned On" https://www.google.com/settings/security/lesssecureapps

2) Enable login from other timezone/IP for your google account https://g.co/allowaccess