Click here to Skip to main content
15,395,360 members
Home / Discussions / C#
   

C#

 
QuestionUpdate SQL table using CLR Pin
IT - Researcher22-Jun-16 21:38
MemberIT - Researcher22-Jun-16 21:38 
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
MemberIT - 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 
GeneralRe: Programmatically Change Windows Photo View Language Pin
Pete O'Hanlon22-Jun-16 21:31
mvaPete O'Hanlon22-Jun-16 21:31 
AnswerRe: Programmatically Change Windows Photo View Language Pin
Bernhard Hiller22-Jun-16 22:04
MemberBernhard Hiller22-Jun-16 22:04 
QuestionI need some help using Exchange EWS with C# Pin
turbosupramk322-Jun-16 12:02
Memberturbosupramk322-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
Memberturbosupramk322-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
Memberturbosupramk323-Jun-16 4:41 
GeneralRe: I need some help using Exchange EWS with C# Pin
turbosupramk323-Jun-16 5:05
Memberturbosupramk323-Jun-16 5:05 
QuestionVS2015 designer resizes my main form on different development PCs Pin
LenHodder22-Jun-16 6:53
MemberLenHodder22-Jun-16 6:53 
AnswerRe: VS2015 designer resizes my main form on different development PCs Pin
BillWoodruff22-Jun-16 18:12
mveBillWoodruff22-Jun-16 18:12 
GeneralRe: VS2015 designer resizes my main form on different development PCs Pin
LenHodder23-Jun-16 0:38
MemberLenHodder23-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
MemberAgewiz22-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
MemberAgewiz22-Jun-16 11:50 
AnswerRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Afzaal Ahmad Zeeshan22-Jun-16 7:12
mveAfzaal 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
MemberAgewiz22-Jun-16 12:02 
AnswerRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
Afzaal Ahmad Zeeshan22-Jun-16 12:04
mveAfzaal Ahmad Zeeshan22-Jun-16 12:04 
AnswerRe: Whenever code shows "Console.WriteLine..." replace with textbox Pin
BillWoodruff22-Jun-16 19:23
mveBillWoodruff22-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.