I have a web server at home running IIS 10 and .Net 4.8.
I am trying to send an email through a C#.Net, using the following yahoo stmp service call.
However, I cannot seem to get it to work? Whenever I try to execute the following code, the web page seems to be loading for about 30 seconds, then returns an "SMTP Server returned an invalid response" error message, which apparently doesn’t mean anything specific? This is getting pretty frustrating as I’ve been on this for over 4 hours now… so thanks for any help!
using (MailMessage mm = new MailMessage("[email protected]", "[email protected]"))
{
mm.Subject = "test";
mm.Body = "testing maudine...";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.mail.yahoo.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("[email protected]", "*******");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 465;
try
{
smtp.Send(mm);
}
catch(SmtpException ex)
{
string p = "";
}
}
3
Answers
Send your email asynchronously and format your code to dispose client properly.
Port 465 isn’t supported by System.Net.Mail.SmtpClient –
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.enablessl.aspx
You could try using port 587 instead (if Yahoo supports it) and disable SSL.
try using application password instead account password. You can generate application password in account settings.