My code is below:
MailMessage mail = new MailMessage();
mail.To.Add("******");
mail.CC.Add("*****");
mail.From = new MailAddress("*******");
mail.Subject = "Salesforce Credential for ";
mail.SubjectEncoding = Encoding.UTF8;
string Body = "<html><head></head><body>Hi,<br> Project Name: "
+ " <br> Username : "
+ " <br> Password : "
+ " <br> Security Token : ";
mail.Body = Body;
mail.BodyEncoding = Encoding.UTF8;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "webmail.***************.**.**";
string uid = "***********";
string pwd = "*********";
smtp.Credentials = new System.Net.NetworkCredential(uid, pwd);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
// without this I get: The remote certificate is invalid according to the validation procedure.
smtp.ClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate2(@"********"));
//Or your Smtp Email ID and Password
smtp.EnableSsl = true;
smtp.Send(mail);
But I got this error:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond