Send Email Using ASP.NET Core
Process Of Send Email With The Attachment Using ASP.NET Core.
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 :)