Click here to Skip to main content
15,861,125 members
Home / Discussions / C#
   

C#

 
QuestionRe: Update SQL table using CLR Pin
Gerry Schmitz23-Jun-16 12:44
mveGerry Schmitz23-Jun-16 12:44 
AnswerRe: Update SQL table using CLR Pin
IT - Researcher23-Jun-16 18:56
IT - Researcher23-Jun-16 18:56 
GeneralRe: Update SQL table using CLR Pin
Gerry Schmitz24-Jun-16 3:44
mveGerry Schmitz24-Jun-16 3:44 
QuestionProgrammatically Change Windows Photo View Language Pin
Kevin Marois22-Jun-16 13:24
professionalKevin Marois22-Jun-16 13:24 
AnswerMessage Closed Pin
22-Jun-16 20:23
Member 1259925622-Jun-16 20:23 
GeneralRe: Programmatically Change Windows Photo View Language Pin
Pete O'Hanlon22-Jun-16 21:31
subeditorPete O'Hanlon22-Jun-16 21:31 
AnswerRe: Programmatically Change Windows Photo View Language Pin
Bernhard Hiller22-Jun-16 22:04
Bernhard Hiller22-Jun-16 22:04 
QuestionI need some help using Exchange EWS with C# Pin
turbosupramk322-Jun-16 12:02
turbosupramk322-Jun-16 12:02 
With this code I keep receiving the error message saying :

"
The request failed. The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
"

Does anyone have any ideas on how I can get my C# program to send emails via EWS in my Exchange environment?

Thanks



C#
using System.Net;
using System.Net.Mail;
using Microsoft.Exchange.WebServices;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;



C#
        private void emailNotifyUser ()
        {
Microsoft.Exchange.WebServices.Data.ExchangeService service = new Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2010_SP1);
            service.Credentials =
                new Microsoft.Exchange.WebServices.Data.WebCredentials("you@you.com", "password1", "domain.com);
            service.TraceEnabled = true;
            service.TraceFlags = Microsoft.Exchange.WebServices.Data.TraceFlags.All;
            service.Url = new Uri("HTTPS://xxxxxxx/EWS/Exchange.asmx"); // https://xxxxxxx.xxx/autodiscover/autodiscover.xml
            //service.AutodiscoverUrl(To,
            //    RedirectionUrlValidationCallback);
            //ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback
            //(
            //   delegate { return true; }
            //);
            // trust sender
            //System.Net.ServicePointManager.ServerCertificateValidationCallback
            //                = ((sender, cert, chain, errors) => cert.Subject.Contains("nsc-cas-01"));
            ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateRemoteCertificate);
            Microsoft.Exchange.WebServices.Data.EmailMessage email = new Microsoft.Exchange.WebServices.Data.EmailMessage(service);
            email.ToRecipients.Add(To);
            email.Subject = "HelloWorld";
            email.Body = new Microsoft.Exchange.WebServices.Data.MessageBody("First email using EWS Managed API");
            email.Body.BodyType = Microsoft.Exchange.WebServices.Data.BodyType.HTML;
            email.Send();
}



C#
private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors policyErrors)
{
    bool result = false;
    if (cert.Subject.ToUpper().Contains("cas-server-name"))
    {
        result = true;
    }

    return result;
}

AnswerRe: I need some help using Exchange EWS with C# Pin
Dave Kreskowiak22-Jun-16 12:52
mveDave Kreskowiak22-Jun-16 12:52 
GeneralRe: I need some help using Exchange EWS with C# Pin
turbosupramk322-Jun-16 13:03
turbosupramk322-Jun-16 13:03 
GeneralRe: I need some help using Exchange EWS with C# Pin
Dave Kreskowiak22-Jun-16 17:56
mveDave Kreskowiak22-Jun-16 17:56 
GeneralRe: I need some help using Exchange EWS with C# Pin
turbosupramk323-Jun-16 4:41
turbosupramk323-Jun-16 4:41 
GeneralRe: I need some help using Exchange EWS with C# Pin
turbosupramk323-Jun-16 5:05
turbosupramk323-Jun-16 5:05 
QuestionVS2015 designer resizes my main form on different development PCs Pin
LenHodder22-Jun-16 6:53
LenHodder22-Jun-16 6:53 
AnswerRe: VS2015 designer resizes my main form on different development PCs Pin
BillWoodruff22-Jun-16 18:12
professionalBillWoodruff22-Jun-16 18:12 
GeneralRe: VS2015 designer resizes my main form on different development PCs Pin
LenHodder23-Jun-16 0:38
LenHodder23-Jun-16 0:38 
AnswerRe: VS2015 designer resizes my main form on different development PCs Pin
Luc Pattyn23-Jun-16 11:12
sitebuilderLuc Pattyn23-Jun-16 11:12 
QuestionWhenever code shows "Console.WriteLine..." replace with textbox Pin
Agewiz22-Jun-16 6:46
Agewiz22-Jun-16 6:46 
QuestionRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Eddy Vluggen22-Jun-16 7:00
professionalEddy Vluggen22-Jun-16 7:00 
AnswerRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Agewiz22-Jun-16 11:50
Agewiz22-Jun-16 11:50 
AnswerRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Afzaal Ahmad Zeeshan22-Jun-16 7:12
professionalAfzaal Ahmad Zeeshan22-Jun-16 7:12 
PraiseRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Eddy Vluggen22-Jun-16 8:04
professionalEddy Vluggen22-Jun-16 8:04 
GeneralRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Agewiz22-Jun-16 12:02
Agewiz22-Jun-16 12:02 
AnswerRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Afzaal Ahmad Zeeshan22-Jun-16 12:04
professionalAfzaal Ahmad Zeeshan22-Jun-16 12:04 
AnswerRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
BillWoodruff22-Jun-16 19:23
professionalBillWoodruff22-Jun-16 19:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.