In today’s newsletter we are going to discuss
Introduction of MailKit
Benefits of using it
Implementing it in .NET 6
Introduction
An open source Nuget package used to send emails , it has more than 80M downloads on nuget store.
Benefits of using MailKit library
Following are the benefits of using this library:
Cross platform
Open source
High performant
Improved security by supporting SSL/TLS
How to implement it in .NET 6
Step 1: Install the MailKit Nuget Package
Step 2: Set up your SMTP server details
I have created a EmailConfiguration
section in my appSettings
and added all necessary information , I am using gmail to send emails so that is why host is smtp.gmail.com
One important thing that you should keep in mind that the password written above is not password of your Gmail account rather it is a password that you generated for sending emails
To generate this password follow these steps
Open Gmail —> Click on Manage Google Account —> In search google account section , type App Passwords —> This window will show up
For app select Mail and for device select windows computer , then click on generate and it will show you an auto generated password put that password in appsetting
Step 3: Create a new Service for Email
If you don’t know about how to read values from appsetting via IOption check this Post
Step 4: Register Dependencies
Register dependencies of your EmailService
and EmailConfiguration
Now inject IEmailService
where you need it and you are good to go.
Whenever you’re ready , there are 4 ways I can help you
Promote yourself to 5400+ subscribers by sponsoring my Newsletter
Become a Patron and get access to 130+ .NET Questions and Answers
Get FREE eBook from Gumroad that contains 30 .NET Tips (2500+ downloads)
Book a one hour 1:1 Session and learn how I went from 0-29K on LinkedIn in 8 months , Book here
Special Offers 📢
Ultimate ASP.NET Core Web API Second Edition - Premium Package
10% off with discount code: 9s6nuez