I am trying to test sending an email to my own company email id. We have Outlook hosted on Exchange server. I used the following code (replacing my email id with a random one due to privacy reasons):
using System;
using Microsoft.Exchange.WebServices.Data;
namespace TestEmail
{
class Program
{
static void Main(string[] args)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.UseDefaultCredentials = true;
//service.Credentials = new WebCredentials("user1@contoso.com", "password");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("xxx@yyy.com", RedirectionUrlValidationCallback);
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("xxx@yyy.com");
email.Subject = "Test mail";
email.Body = new MessageBody("Sending the test email");
email.Send();
}
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}
}
}
}
When I run this, I get an error which says "AutodiscoverConfiguration failed: Web Exception (The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel).
I am not aware of how Exchange Server's security is set up at my workplace, because it is handled by a different team.
How do I resolve this issue?