Reputation: 285
I want to test sending emails in my web app which is using .net core 3 with C#.
The issue is I am on a corporate network which blocks port 587 (for now).
I saw an article which says you can use this
mailClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
But I am hosting with .net core which is not configured for IIS so I get an error "IIS delivery is not supported".
Is IIS the only way to test sending emails locally?
Upvotes: 6
Views: 3733
Reputation: 33
You can run a moq (fake) SMTP server as part of your app. The emails won't be delivered to the recipients but stored in-memory so they can be inspected.
I'm the author of the SmtpMoq.NET for .NET Core that does exactly that. Please check here and here for details how to utilize it.
Additional benefit will be that you can automate your integration tests and verify if the emails are correctly sent.
Hope this helps.
Upvotes: 2
Reputation: 3874
You can specify the option SmtpDeliveryMethod.SpecifiedPickupDirectory
The mail will be picked up from the directory specified in the property SmtpClient.PickupDirectoryLocation
You can see the reference pages for:
For example:
var client = new SmtpClient {
DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory,
PickupDirectoryLocation = @"c:\myMailFolder"
};
Upvotes: 8