I\'m trying to write a basic console app that will send an email. The problem is that I keep getting the Socket exception:
An attempt was made to acc
I changed to MailKit.Net.Smtp.SmtpClient. It gave better errors and I was able to get the emails to work.
using MimeKit;
using MailKit.Net.Smtp;
using System.Net;
using (var client = new SmtpClient())
{
client.Connect
(
Context.Settings.SMTPServer,
Convert.ToInt32(Context.Settings.SMTPPort),
MailKit.Security.SecureSocketOptions.None
);
//ignore ssl errors
client.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
// Note: only needed if the SMTP server requires authentication
if (Context.Settings.SMTPAuthenticate)
{
client.Authenticate
(
new NetworkCredential
(
Context.Settings.SMTPUserName,
Context.Settings.SMTPPassword,
Context.Settings.SMTPDomain
)
);
}
await client.SendAsync(message);
client.Disconnect(true);
}