I.m working on a Windows app where the user has to enter a password. I also have a "Forgot Password" link. on the window. When that's clicked, I have the user enter their email address and click a Submit button. Every time they enter an email address and click the button, I get the error message:
SmtpException has occured: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required.
The code I'm using is:
try { Cursor = Cursors.WaitCursor; MailAddress from = new MailAddress("[email protected]", "Bob Gatto"); MailAddress to = new MailAddress("[email protected]", "Bob Gatto"); MailMessage eMsg = new MailMessage(from, to); eMsg.Subject = "Your Password Renewal Request"; eMsg.IsBodyHtml = true; eMsg.Body = "This is the body."; SmtpClient eClient = new SmtpClient("smtp.gmail.com", 587); eClient.EnableSsl = true; eClient.UseDefaultCredentials = true;gmail // The following email and password used is that of my own gmail email // that I use for my own personal email. eClient.Credentials = new System.Net.NetworkCredential("<[email protected]>", "<MyPassword>"); eClient.Send(eMsg); } catch (SmtpException ex) { throw new ApplicationException("SmtpException has occurred: " + ex.Message); } catch (Exception ex) { throw ex; } What else needs to be done?

throw ex;is an anti-pattern. It strips useful information from the exception before re-throwing it. To re-throw the original exception just usethrow;Or remove thatcatchblock entirely since it isn't doing anything.In the Port field, enter one of the following numbers: For SSL, enter 465. For TLS, enter 587.