MailKit not Sending Emails in Production Enviroment with Dot Net Core 2.2

Problem: When programming in .Net Core 2.2 Web Application, MailKit Smtp Library sends emails in the Development Mode but when the app is deployed to production, the emails do not go through.


Login to See the Rest of the Answer

Answers: There could be many variables that could make the emails not go through. Below are the possibilities, it is up to you and your project to see which one might be causing the problem:

1. Check that your Server has valid certificates, many out going smtp's will reject the request if the message is not over SSL or TLS encrypted.

2. If you are using Dot Net Core 2.2 with dependency injection, check that you are not instatieting a controller, the reason of introducing or putting much emphasis on DI (depency injection) is to cut down on class instatietions. In thic scenerial only call the Interface (IEmailSender) and access the function that sends the emails.
- You might find that IEmailSender (which is an interface) gets enherited by a Repository Class called EmailSenderRepository.cs this class implements all the functions defined in the IEmailSender.cs interface. Instead of Instatieting EmailSenderRepository rep = new EmailSenderRepository(); just call IEmailSender.FunctionThatSendsEmails(). The way you will have access to the Interface is by the magic of Dependecy Injection, you would have injected this IEmailSender Interface class through the constructor of the Controller you are in.

Enjoy and do leave a comment if this helped you.

.Net 7

Leu said:

Thank you.

Posted On: April 25, 2020 6:57:37 AM

© 2024 - ErnesTech - Privacy
E-Commerce Return Policy