If you're trying to send email from a console application (your higher-level problem), I recommend using PostMark. Why:
- NuGet - You can get the PostMark NuGet package and send email with a nice API. Convenient and simple.
- Not marked as SPAM - You can configure your "server" with verification (including spf and signing). So your email will more likely reach the destination in their inbox rather than their SPAM box.
- Free - to a point. I think it's 1000 emails for free then $1 per 1000. So that's pretty good. Compare that to any other vanilla SMTP server for rent. PostMark is cheap
- Consistent - From Workstation DEV to server LIVE, the PostMark API is consistently accessible. I cannot stress how good that is. Often a server host will offer SMTP server endpoint but it will only work from inside their network, meaning you have to configure another SMTP server when you're doing DEV work on your workstation (or it simply wont work).
- Async Interface - I'm not sure if built-in smtp client in .Net is async...
- Tracking - Hey look at that, they have a tracking feature built-in. That's snazzy.
Example code for sending (source):
var message = new PostmarkMessage()
{
To = "recipient@example.com",
From = "sender@example.com",
TrackOpens = true,
Subject = "A complex email",
TextBody = "Plain Text Body",
HtmlBody = "<html><body><img src=\"cid:embed_name.jpg\"/></body></html>",
Tag = "business-message",
Headers = new HeaderCollection{
{"X-CUSTOM-HEADER", "Header content"}
}
};
var imageContent = File.ReadAllBytes("test.jpg");
message.AddAttachment(imageContent, "test.jpg", "image/jpg", "cid:embed_name.jpg");
var client = new PostmarkClient("server token");
var sendResult = await client.SendMessageAsync(message);