we are going to discuss following points:
- 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
Step 4: Register Dependencies
Register dependencies of your EmailService
and EmailConfiguration
Now inject IEmailService
where you need it and you are good to go.
0 comments:
Post a Comment