Anish varma Adduri
Anish varma Adduri

Reputation: 599

The SMTP server requires a secure connection or the client was not authenticated in C# ASP.NET

I am trying to send an email but i am getting authentication failure.

Do we need any specific type of authentication for Google mail.

[Error in Browser][1]
     // Created Mail message and taken inputs
    MailMessage mail = new MailMessage(from,to,subject,message);
    // Used SMTP Client
    SmtpClient client = new SmtpClient();
    // Google Port
    client.Port = 587;
    client.Credentials = new NetworkCredential(From.Text, password.Text);
    client.UseDefaultCredentials = true;
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.EnableSsl = true;
    client.Send(mail);
    Label.Text = "Sent Successful";

I am getting error near Send(mail)

Upvotes: 0

Views: 732

Answers (1)

DSN
DSN

Reputation: 397

You're not setting the SMTP server address?

Assuming your credentials are correct then you should use SmtpClient client = new SmtpClient("smtp.gmail.com") and client.Port = 465. 587 is for TLS

Upvotes: 1

Related Questions