Send Email Using ASP.NET Core

Process Of Send Email With The Attachment Using ASP.NET Core.

Pritomsarkar
.Net Programming
Published in
3 min readMay 13, 2021

--

Overview

In this article, you will see how to send an email in ASP.NET Core using the MailKit email client library.

Prerequisites

I expect you to have knowledge of object-oriented programming concepts in C#. I assume you know .NET Core concepts especially the MVC pattern also.

To code along with me, you will have to install the .NET Core 2.2, as well as Visual Studio. You can also use another IDE instead of a visual studio. You can find a link to the Github repository end of this article.

Environment Setup

Open Visual Studio 2017. Create a project “Asp.Net Core Web Application(.Ne Core)” with an MVC pattern Template. You Can name this project whatever you want.

Configure Asp.Net Core

Now we’ll install the dependencies if it’s not installed already in your IDE.

Microsoft.AspNetCore.Razor.Design

Microsoft.VisualStudio.Web.CodeGeneration.Design

Microsoft.AspNetCore.App

MailKit

So you successfully installed the mailkit NuGet.Now you have to go to the HomeController section to implement mail functionality.

EmailView

Before running your application you have to ensure that less secure apps: ON and must do this process both in your email.

Now time to run your application.

Now Check your mail.

So you have successfully sent mail.

But if you want to send an email with an attachment, just add some code in your HomeController by following the below code.

Above code, here I actually used another method in HomeController for sent mail with attachment. and make sure your wwwroot folder has pdf file.

Now run your application and check the mail.

Conclusion

So you successfully send a mail with an attachment. Hope you guys enjoy this article. You can download the source code to my Github Repository.

Happy Coding :)

--

--

.Net Programming
.Net Programming

Published in .Net Programming

Explore the .Net with the latest in C# from basic to advanced, including .Net versions 9, 8, 6, 5, Core 3.1, .Net Framework, ASP.NET Core, MVC, design patterns, OOPS, and SOLID principles. Get top tutorials, best practices, and hands-on code examples on GitHub.

No responses yet