How to send email using C# without any nugget Package

Since you are reading this post, you want to send an email using C#.
Now let’s start coding.

Create new Project — Console Application

Create a new .NET Console Application project.

You can name your project anything! I would prefer to name it EmailSender.

Start Coding!

Create a new class in your project and add a new method with 5parameters.

Now let's understand the code written above.

There are 5 parameters in the method SendEmail.

senderEmail: email of the sender.

senderPassword: password of the sender.

receiverEmail: email of the person whom to send the mail.

body: This parameter will have the body of your mail, it can also have html string.

subject: Subject of the mail.

We using MailMessage class which is in directory System.Net.Mail.

IsEmailValid() will check if the given emails are valid or not, this will ensure better exception handling.

Use Case

Call the method, and you should see a new mail in your inbox in a few seconds.


System.Net.Mail.SmtpException: ‘The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required.

The above error can occur because of two reasons:

  1. Your credentials are incorrect.

To solve this error, just check your email and password once again.

2. Your Gmail account is not allowed to be access by less secure apps.

To solve this error, go to your Google account settings ⇾Security ⇾ Turn on Less secure app access.

Click here

Just turn it ON.

Apart from this, if you have any other errors or exception Let me know in the comment section, I’ll be glad to help you out :)

You can also access the full project in the GitHub Repository.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Deploy laravel project using envoy

How to Provision an AWS on-demand EC2 instance.

Backstage Plugins by Example: Part 3

Why good devops still exists in 2022 and how it influences your business

Summary AMA with Brian Fox

Check Your PySpark Abilities By Solving This Quick Challenge

Head in the Clouds…

Jupyter Notebook in Windows subsystem for Linux (WSL)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mohammed Aquib Ansari

Mohammed Aquib Ansari

C# Developer

More from Medium

Using OAuth 2.0 with LINQ to Twitter

A user authorizing your app.

New release of Visual Studio 2022

Is it possible to gain much more clean code with the Linq? /Linq ile daha temiz kod mümkün mü?)

Breaking out of virtual chains with Slay