When you are getting the below error.
SMTP server
requires a secure connection or the client was not authenticated. The server
response was : 5.5.1 Authentication Required.
Then you need
to configure your email ID using Microsoft Dynamics CRM Email Router
Configuration Manager.
Download Email
Router Configuration Manager according to your system configuration
And Install it
in your system, then configure your email( from which mail you want to send
mails in code).
When you
install the Microsoft Dynamics CRM Email Router Configuration Manager,
Click on
Then click on Configuration files-àNewà then you will get the following screen.
Under Access
Credentials you need to specify email id and password( which email you want to
configure) then click on publish then write the following code.
Email sending in C# gmail
using (MailMessage mm = new MailMessage("from@gmail.com", "to@gmail.com"))
{
mm.Subject = "Subject Text";
mm.Body = "Body Text";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("from@gmail.com", "pwm");
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate,
X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtp.UseDefaultCredentials = false;
smtp.Credentials = NetworkCred;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Port = 587;
smtp.Send(mm);
//ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
No comments:
Post a Comment