---
title: "The SMTP server requires a secure connection when i try to send an email"  
description: "The SMTP server requires a secure connection when i try to send an email"  
author: "Anonymous User"  
published: 2014-09-29  
updated: 2014-09-29  
canonical: https://www.mindstick.com/forum/2279/the-smtp-server-requires-a-secure-connection-when-i-try-to-send-an-email  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# The SMTP server requires a secure connection when i try to send an email

I create a mail class to send emails.

```
public void SendEmail(string subject, string messageBody, string toAddress){    MailMessage mail = new MailMessage();    mail.To.Add(toAddress);    //mail.To.Add("amit_jain_online@yahoo.com");    mail.From = new MailAddress("noreply3ncra@gmail.com");    mail.Subject = subject;    string Body = messageBody;    mail.Body = Body;    mail.IsBodyHtml = true;    SmtpClient smtp = new SmtpClient();    smtp.UseDefaultCredentials = false;     smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address    smtp.Credentials = new System.Net.NetworkCredential         ("noreply3ncra@gmail.com", "********");    //Or your Smtp Email ID and Password    smtp.EnableSsl = true;    smtp.Send(mail);}
```

But I got this error:

The [SMTP server](https://answers.mindstick.com/qa/116515/top-smtp-server-providers-for-reliable-email-sending) requires a [secure connection](https://www.mindstick.com/forum/159459/sslhandshakeexception-when-establishing-a-secure-connection-in-a-mern-application) or the [client](https://www.mindstick.com/articles/23198/3-steps-to-ensure-that-your-client-portal-is-impeccable) was not authenticated. The [server response](https://answers.mindstick.com/qa/93903/what-is-the-server-response-in-ajax-and-why-we-are-uses-this-property) was: 5.5.1 [Authentication](https://www.mindstick.com/blog/177/authentication-and-authorization-in-asp-dot-net) Required.

So I have to sign into Gmail and enter the [captcha](https://www.mindstick.com/news/655/users-to-spend-500-year-s-per-day-on-captcha) code and after this every thing is going to be ok.

What should I do?

## Replies

### Reply by Sumit Kesarwani

Hi jay, \

Add port no also to your code as:

smtp.Port = 587;


---

Original Source: https://www.mindstick.com/forum/2279/the-smtp-server-requires-a-secure-connection-when-i-try-to-send-an-email

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
