2

I am using following code to send email. The Code does not working it getting the error message

try
{
    MailMessage message = new MailMessage(mFrom, "xyz@gmail.com",mSubject,mMsg);
    SmtpClient mySmtpClient = new SmtpClient("smtp.gmail.com",587);
    mySmtpClient.Credentials = ICredentialsByHost)CredentialCache.DefaultNetworkCredentials;
    mySmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    mySmtpClient.UseDefaultCredentials = true;
    mySmtpClient.EnableSsl = true;
    mySmtpClient.Send(message);
}
catch (FormatException ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (SmtpException ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

The following SmtpException exception is been catched

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

Thanks...

Milind
  • 17
  • 4
  • 1
    http://stackoverflow.com/questions/18503333/the-smtp-server-requires-a-secure-connection-or-the-client-was-not-authenticated?rq=1 – zonabi Feb 06 '16 at 06:13

1 Answers1

0

Please configure the required mail settings in the web.config based on the delivery method or host that you use.

Have look at the following URL how to configure smtp settings in web.config