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...