I'm working on an app where I would like to send a crash report to an email if a global threading exception is invoked. However, every time I try to send this email, I get the error
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at. <-- the error message ends here which seems weird.
My exception event handler looks like this:
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        MailAddress fromAddress = new MailAddress("user@domain.com", "Mary");
        MailAddress toAddress = new MailAddress("user@domain.com", "Sam");
        const string fromPassword = "password";
        const string subject = "Exception Report";
        Exception exception = e.ExceptionObject as Exception;
        string body = exception.Message + "\n" + exception.Data + "\n" + exception.StackTrace + "\n" + exception.Source;
        var smtp = new SmtpClient
        {
            Host = "smtp.gmail.com",
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
        };
        using (MailMessage message = new MailMessage(fromAddress, toAddress)
        {
            Subject = subject,
            Body = body
        })
        {
            try
            { 
                smtp.Send(message);
            }
           catch(Exception err)
            {
                Console.WriteLine("Could not send e-mail. Exception caught: " + err);
            }
        }
    }
Does anyone know why I would be getting this server authentication error?
 
    