0
votes

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:&nbsp;"
        + " <br> Username &nbsp;&nbsp;&nbsp;&nbsp;:&nbsp; "
        + " <br> Password &nbsp;&nbsp;&nbsp;&nbsp;:&nbsp; "
        + " <br> Security&nbsp;Token &nbsp;&nbsp;&nbsp;&nbsp;:&nbsp; ";
        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

1

1 Answers

0
votes

You are using SMTP not HTTP to send this message. SMTP typically does not use proxies but rather relays. I suspect the fundamental issue, based on your code, is that webmail.whateaver.xx.yy is the exchange web services endpoint and it is not capable nor configured to expose the SMTP port publicly. You'll need to get with whoever controls that system and work out what the proper means of access are.

If they can't expose SMTP -- which is higly likely, I would laugh at your face if you came and asked me to do that -- you probably will need to find an alternate outbound SMTP option or use Exchange Web Services to send the mail. See nuget for EWS client libraries.

Finally, while I've got the floor, please do the world a favor and do not email passwords around.