Using asp.net core 3.1 I can send email using this code:
Code snippet 1 using System.Net.Mail.SmtpClient
using (System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient())
{
smtp.Host = "mail.my-real-domain-name.com";
smtp.EnableSsl = false;
NetworkCredential credential = new NetworkCredential(emailModel.From,
emailModel.Password);
smtp.UseDefaultCredentials = false;
smtp.Credentials = credential;
smtp.Send(mm);
}
but when I try to send email using MailKit it doesn't connect to mailserver
Code snippet 2 in MailKit documentation
using (var client = new MailKit.Net.Smtp.SmtpClient())
{
client.Connect("mail.my-real-domain-name.com",0,false);
client.Authenticate(emailModel.From, emailModel.Password);
client.Send(message);
client.Disconnect(true);
}
What's the equal of Code snippet 1 using MailKit?
None of below lines worked so I want to know how to send email without specifying port number using MailKit. It doesn't throw any error, just doesn't connect, I mean it stays in client.Connect line.
// client.Connect("mail.my-real-domain-name.com", 465);
// client.Connect("mail.my-real-domain-name.com", 465, true);
// client.Connect("mail.my-real-domain-name.com", 25, false);
// client.Connect("mail.my-real-domain-name.com", 2525, false);
// client.Connect("mail.my-real-domain-name.com", 587,MailKit.Security.SecureSocketOptions.StartTls);