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...
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.