Reputation: 73
I need to set up a custom application at my workplace, to read email subject lines from a specific Exchange Server mailbox, and redirect them based on the content. I wrote the following code to test connectivity:
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("[email protected]", "password");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback);
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("[email protected]");
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;
}
}
}
}
But the workplace security settings disallow exposing autodiscovery endpoints, and I was informed that this setting can't be changed.
Is there any other way for me to connect to the Exchange server, without using AutoDiscover?
This is a follow up to my previous question SSL/TLS error when connecting to Exchange from C#
Upvotes: 1
Views: 5849
Reputation: 22032
If you know you EWS URL you can just hardcode the setting and get rid of your Autodiscover
code e.g.
Remove
//service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback);
and use:
service.Url = new Uri("https://computername.domain.contoso.com/EWS/Exchange.asmx");
See also https://msdn.microsoft.com/en-us/library/office/dn509511(v=exchg.150).aspx
Upvotes: 1
Reputation: 66341
Keep in mind that Outlook 2016 will not even work if autodiscover XML is not available. You really need to enable autodiscover to make sure Outlook works.
"security settings disallow exposing autodiscovery endpoints" - I am curious what are the possible security implications of exposing autodiscover endpoints.
Upvotes: 0