Reputation: 1
I got tasked with fixing an app whose current server is going to lose support sooner than later. It now uses smtp.mundo-r.com (which belongs to a Spanish ISP) and the program was using port 25 with SSL disabled. As far as I know, the new server is more secure (I know next to nothing when it comes to this kind of stuff, might I add). So when I set the program to use smtp.cloud.mundo-r.com (the new server) the emails aren't sent and I get this error:
SMTP EXCEPTION: The SMTP server requires a secure connection or the client did not authenticate. The server's response was: 5.7.0 Must issue a STARTTLS command first
Now, the method that's handling the email sending is:
public static bool SendSystemEmail(string emailTo1, string emailTo2, string subject, string body)
{
var ccAddress = new MailAddress(SystemAddress);
var mail = new MailMessage {From = new MailAddress(SystemAddress), IsBodyHtml = true};
mail.To.Add(new MailAddress(emailTo1));
//mail.To.Add(new MailAddress(emailTo2));
var smtpClient = new SmtpClient
{
EnableSsl = true,
Port = 587,
DeliveryMethod = SmtpDeliveryMethod.Network,
Host = SystemServer,
Credentials = new NetworkCredential(SystemAddress, SystemPassword)
};
mail.CC.Add(ccAddress);
if (emailTo2.Contains("@"))
{
mail.CC.Add(new MailAddress(emailTo2));
}
mail.Subject = subject;
mail.Body = body;
try {
smtpClient.Send(mail);
return true;
}
catch (SmtpException smtpEx) {
Exception orEx = GetOriginalException(smtpEx);
Console.Write("SMTP EXCEPTION: " + smtpEx.Message + "\nOriginal exception: " + orEx.Message);
return false;
}
catch (InvalidOperationException ioe)
{
Exception orEx = GetOriginalException(ioe);
Console.Write("INVALID OPERATION EXCEPTION: " + ioe.Message + "\nOriginal exception: " + orEx.Message);
return false;
}
catch (Exception e)
{
Exception originalEx = GetOriginalException(e);
Console.Write("MESSAGE NOT SENT: " + e.Message + "\nOriginal Exception: "+ originalEx.GetType().Name + " -> "+ originalEx.Message);
return false;
}
}
So... I honestly do not know what's happening. The credentials are being taken from a table in the database that has one unique row and the password field is empty, though with the previous server it works perfectly fine. Sorry if all this looks messy, first time posting in here and kinda new to the job. And thank you all beforehand!
I did try the connection through Powershell with
telnet smtp.cloud.mundo-r.com
EHLO example
STARTTLS
And it does connect, so I don't know.
Upvotes: 0
Views: 35