Extracting/Scanning emails from Outlook using C# - c#

I'm trying to make a windows form application that can be "hidden" in the taskbar (like WiFi and so on), equipped with a timer, and that every 10 seconds it scans my email inbox in Outlook.
The first part works fine, but I can't get the scan to work. At first i just want to extract the names of email subjects and put them into a text file, just to test the code. But in the end i'd like to scan one particular inbox (i have several on my outlook, like 5 or 6, with different mail address associeted, and i can't find anything on the internet to target one of them) and make a popup or something when particular email are received.
Anyway, this is the code i have so far:
public static bool isRunning = false;
public Form1()
{
InitializeComponent();
System.Timers.Timer timer = new System.Timers.Timer(10000);
timer.Elapsed += OnTimedEvent;
timer.Enabled = true;
}
private void Hide_Click(object sender, EventArgs e)
{
this.Hide();
notifyIcon1.Visible = true;
}
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
this.Show();
notifyIcon1.Visible = false;
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Outlook.Application app = null;
Outlook.MAPIFolder inbox = null;
Outlook._NameSpace ns = null;
if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
{
try
{
app = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
ns = app.GetNamespace("MAPI");
List<Outlook.MailItem> ReceivedEmail = new List<Outlook.MailItem>();
List<string> titles = new List<string>();
foreach (Outlook.MailItem mail in inbox.Items)
{
ReceivedEmail.Add(mail);
}
foreach (Outlook.MailItem mail in ReceivedEmail)
{
titles.Add(mail.Subject.ToString());
}
File.WriteAllLines("C://Users/A222946/Desktop/allMails.txt", titles);
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show(ex.Message);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show("Please, start outlook..");
}
}
}
The error i find when i'm running this is the following:
Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)
I tried with and without administrator rights, same error.
Update
So after some changes it looks like this now:
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Outlook.Application app = new Outlook.Application();
Outlook.MAPIFolder inbox = null;
Outlook._NameSpace ns = null;
Outlook.Items items = null;
if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
{
try
{
app = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
ns = app.GetNamespace("MAPI");
inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
items = inbox.Items;
List<Outlook.MailItem> ReceivedEmail = new List<Outlook.MailItem>();
List<string> titles = new List<string>();
foreach (Object obj in items)
{
if (obj is Outlook.MailItem)
{
ReceivedEmail.Add((Outlook.MailItem)obj);
}
}
foreach (Outlook.MailItem mail in ReceivedEmail)
{
titles.Add(mail.Subject.ToString());
}
File.WriteAllLines("C://Users/A222946/Desktop/allMails.txt", titles);
}
catch (COMException ex)
{
MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show("Please, start outlook..");
}
}
But i still have this error:
object reference not set to an instance of an object
Also, do you have any idea how i could target one particular mailbox? Example: "abcdefg#blabla.com"

I think the COM components are not accessible. COM components are used by some of the Windows components(like MS Office).You need to make use of STAThreadAttribute.
[STAThread]
static void Main(string[] args)
{
// etc..
}
I think this should fix the issue.

Firstly, this really needs to be an Outlook COM addin (which runs when Outlook runs), not a separate exe that detects when Outlook is running.
That being said, you are using Namespace.GetDefaultFolder. What you need to be using is Store.GetDefaultFolder (where Store is retrieved from the Namespace.Stores collection) if the store is already opened in the profile. Or Namespace.CreateRecipient / Namespace.GetSharedDefaultFolder if the store is not already opened in the profile.

Related

SVN credentials

I have an issue where I keep getting an error
No provider registered for 'svn.ssl.server' credentials
I am using the same code that works on another SVN server, but a new server I setup can't seem to connect even though I can connect no problem through a web browser.
//SVN Client repo sync
public void DownloadSVNStartup(string url, string path)
{
using (SvnClient client = new SvnClient())
{
try
{
client.CleanUp(path); //will go to catch block since there's no working copy yet I
//want to checkout for the first time then next time this part
//will work.
SvnUI.Bind(client, this);
SvnCheckOutArgs sco = new SvnCheckOutArgs();
sco.AllowObstructions = false;
}
catch (Exception ex)
{
MessageBox.Show("Line 88");
MessageBox.Show(ex.ToString());
myLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
}
client.Configuration.SetOption("servers", "global", "http-auth-types", "basic;digest");
client.Authentication.Clear();
client.Authentication.ForceCredentials("user", "password");
try
{
client.Authentication.SslServerTrustHandlers += delegate (object sender,
SvnSslServerTrustEventArgs e)
{
e.AcceptedFailures = e.Failures;
e.Save = false; // Save acceptance to authentication store
};
Object[] args = { url, path };
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += backgroundWorker1_DoWork;
worker.RunWorkerAsync(args);
this.Hide();
}
catch (Exception ex)
{
MessageBox.Show("Line126");
MessageBox.Show(ex.ToString());
myLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
}
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) //connect to the Svn
//server
{
try
{
Object[] arg = e.Argument as Object[];
string url = (string)arg[0];
string path = (string)arg[1];
using (SvnClient client = new SvnClient())
{
client.Authentication.Clear(); // Prevents saving/loading config to/from disk
client.Authentication.ForceCredentials("user", "password");
client.CheckOut(new Uri(url), path); //fails here with the error No provider registered for 'svn.ssl.server' credentials
client.CleanUp(path);
client.Update(path);
client.CleanUp(path);
}
}
catch (Exception ex)
{
MessageBox.Show("Line166", ex.Message.ToString());
MessageBox.Show(ex.ToString());
}
}
I have searched for hours for solutions and can't find anything.
Both servers are setup with same port, same HTTPS settings and created certificates, same VisualSVN server editions.
I have tried only the one solution that I could find as this is not a common issue at all.
This is supposed to fix that error but it doesn't.
client.Authentication.SslServerTrustHandlers += delegate (object sender, SvnSslServerTrustEventArgs e)
{
e.AcceptedFailures = e.Failures;
e.Save = false; // Save acceptance to authentication store
};
I fixed it with adding an event handler for the certificate
private void SslClientCertificateHandlers(object sender, SvnSslClientCertificateEventArgs e)
{
e.Save = true;
e.CertificateFile = #"where you want to save certs";
}

Elegant way to programmatically check if BitLocker is available on system?

I'm currently working on a installer kind of program. It has a system check page where I check if all the requerments are met or not. One requirement is the availability of BitLocker.
Currently I check for BitLocker by trying to create an instance of Win32_EncryptableVolume and then check if an exception is thrown or not.
But I wonder if there is a more elegant way.
My method currently looks basicaly like this:
public static bool IsBitlockerAvaliable()
{
try
{
var path = new ManagementPath
{
NamespacePath = #"\ROOT\CIMV2\Security\MicrosoftVolumeEncryption",
ClassName = "Win32_EncryptableVolume"
};
using (var wmi_class = new ManagementClass(path))
{
foreach (var o in wmi_class.GetInstances())
{
var vol = (ManagementObject) o;
if (vol == null)
throw new Exception("Vol is null");
Debug.WriteLine(vol);
}
}
return true;
}
catch (ManagementException e)
{
// No Admin rights is a different issue
if (e.ErrorCode == ManagementStatus.AccessDenied)
{
throw new AccessViolationException();
}
return false;
}
catch (Exception e)
{
return false;
}
}

Connect to EPSON ePOS t88V printer from .NET UWP

I am trying to connect to an EPSON ePOS t88V printer from my .NET UWP application, using the drivers and SDK found here: https://download.epson-biz.com/modules/pos/index.php?page=prod&pcat=3&pid=36
I have deployed the official UWP sample app (https://download.epson-biz.com/modules/pos/index.php?page=single_soft&cid=5592&pcat=3&pid=36) to the POS, but the application wasn't able to discover the printer.
Then, I tried to build a minimal app, following the code snippets from the user manual:
using System;
...
using Epson.Epos.Epos2;
using Epson.Epos.Epos2.Printer;
namespace PrinterTest1
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
Printer printer = null;
PrinterStatusInfo status = null;
public MainPage()
{
InitializeComponent();
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
try
{
printer = new Printer(Series.TM_T88, ModelLang.Ank);
printer.Received += Printer_Received;
printer.AddText("Deeeeerp.");
await printer.ConnectAsync("TCP:10.10.10.133", Printer.PARAM_DEFAULT); //this line throws an exception
await printer.BeginTransactionAsync();
await printer.SendDataAsync(Printer.PARAM_DEFAULT);
}
catch (Exception ex)
{
}
}
private void Printer_Received(Printer sender, ReceivedEventArgs args)
{
DoStuff();
}
private async void DoStuff()
{
try
{
status = printer.GetStatusAsync().GetResults();
if (status.Connection == Connection.True && status.Online == Online.True)
{
await printer.SendDataAsync(Printer.PARAM_DEFAULT);
}
}
catch (Exception ex)
{
}
}
}
}
but I am still not being able to connect to the printer. I am getting this exception:
{System.Exception: Exception from HRESULT: 0xA0048201 at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at PrinterTest1.MainPage.d__3.MoveNext()}
Take a look at the Universal Windows apps SDK
This allows you to connect to network printers.
See this code
Of course after installing the printer SDK
Printer printer = null;
try
{
printer = new Printer(Series.TM_T82, ModelLang.Ank);
printer.Received += Printer_Received;
printer.Buffer(order);
// Connect to printer through wifi
// Find printer from MAC address
await printer.ConnectAsync("TCP:64:EB:8C:2C:5B:4F", Printer.PARAM_DEFAULT);
await printer.BeginTransactionAsync();
// Send data to the printer
PrinterStatusInfo status = await printer.GetStatusAsync();
if (status.Connection == Connection.True && status.Online == Online.True)
{
await printer.SendDataAsync(Printer.PARAM_DEFAULT);
}
// Haven't figure out issue:
// If not delayed an ERR_PROCESSING is caught
await Task.Delay(1500);
//
await printer.EndTransactionAsync();
await printer.DisconnectAsync();
}
catch (Exception ex)
{
foreach (PropertyInfo prop in typeof(ErrorStatus).GetProperties())
{
if((int)prop.GetValue(null) == ex.HResult)
{
throw new Exception(prop.Name);
}
}
throw new Exception(ex.Message);
}
printer.ClearCommandBuffer();
printer.Received -= Printer_Received;
printer = null;
// Form a receipt from given order to the printer data buffer
public static void Buffer(this Printer printer, Order order)
{
// Receipt header
printer.AddTextAlign(Alignment.Center);
printer.AddTextSize(2, 1);
printer.AddText("MALAY PARLOUR\n");
printer.AddTextSize(Printer.PARAM_DEFAULT, Printer.PARAM_DEFAULT);
printer.AddText("234 PONSONBY RD, AUCKLAND\n");
printer.AddText("GST No: 106-338-302\n\n");
// Order time e.g. 01-01-2017 15:15
printer.AddText(String.Format("{0:dd}-{0:MM}-{0:yyyy} {0:HH}:{0:mm}\n", order.OrderDate));
// Print order details
foreach (OrderDetail od in order.OrderDetails)
{
printer.AddTextAlign(Alignment.Left);
// e.g. 2 * Seafood Laksa $16.50
printer.AddText(String.Format("{0,6} * {1,-22} {2,10:C2}\n",
od.Quantity,
od.Product.ProductName,
od.UnitPrice * od.Quantity));
// If item has remarks, add remarks in a new line
if (!String.IsNullOrEmpty(od.Remarks))
{
printer.AddText("\t" + od.Remarks + "\n");
}
printer.AddText("\n");
}
printer.AddTextAlign(Alignment.Right);
// If order has discount, print subtotal and discount
if (order.Discount != 0)
{
printer.AddText(String.Format("Subtotal: ${0:f2}\n", order.Subtotal));
printer.AddText(String.Format("Discount: {0:P2}\n", order.Discount));
}
// Print total. e.g. EftPos: $38.00
printer.AddTextSize(2, 1);
printer.AddText(String.Format("{0}: ${1:f2}\n\n", order.Payment, order.Total));
// Order footer
printer.AddTextAlign(Alignment.Center);
printer.AddTextSize(Printer.PARAM_DEFAULT, Printer.PARAM_DEFAULT);
printer.AddText("www.malayparlour.co.nz\n\n\n");
// Add a cut
printer.AddCut(Cut.Default);
}
private static void Printer_Received(Printer sender, ReceivedEventArgs args)
{
string callbackCode = Enum.GetName(typeof(CallbackCode), args.Code);
if (callbackCode.Contains("Error"))
{
throw new Exception(callbackCode);
}
}
Please check required device capabilities are enabled on Package.appxmanifest.
Required capabilities depend on how to connect to your printer (almost "Internet (Client & Server)" or "Bluetooth").
https://learn.microsoft.com/ja-jp/windows/uwp/devices-sensors/enable-device-capabilities

c# outlook addin userproperty of first item in collection not found

Outlook 2016
.Net Framework 4.5
i encounter a really strange behaviour:
when i iterate through the items collection of a contact folder in some very special undefined cases (which i do not really understand) some userproperties of the first item of the collection fail to load. However the UserProperties are definitly set.
The approach is following:
I open the contact folder (to which the items will be moved) in outlook.
then i execute the "test"
the execution of the test can be suammrized as following:
click button ->
start thread
iterate through the items (on first iteration no items are present).
add new items{
create item
set userproperty PRE before item is initially saved
save item
move item to desired folder
set userproperty POST after item is moved
save item
}
end thread
click button ->
start thread
iterate through the items (here the userproperty POST sometimes fails to load on the first item of the collection, however when i investigate it, it IS there. It only fails for the first item and succeeds for every other following item).
...END
it seems to me that outlook somehow fails to update the userproperty definitions timely. But note that the first BackgroundWorker thread is already finished when iterating through the items with the second backgroundworker thread.
The problem could be related to the fact that iam viewing the folder in the explorer while the items are added and iterated.
This bug is hard to reproduce and does only occur rarely.
however i'm really missing insight into the inner workings of outlook so i can only speculate.
Idea for workarounds:
I could add an item with all userproperties before moving it. the problem here is that i need to add new userproperties, after the item is initially saved and moved to the folder, in some scenarios.
in few cases the userproperty key is dynamically created (with a pattern) so it wouldn't be optimal to predefine all userproperties.
It's very important that the userProperties are reliably loaded because some important features are based upon them.
Does anybody has a clue how the problem is caused and how to solve it? because this behaviour is driving me crazy.
some Code (not the original but it should contain all the relevant aspects)
//Ribbon
TestNS.TestCaller testCaller;
string folderID = "00000000BDB409934ED327439481EB6E1E1CC4D3010055B62301B58E32478DCD8C0D3FA6304600002C4CA4400000";
public void testButton0_Action(Office.IRibbonControl control)
{
if(testCaller == null){
testCaller = new TestNS.TestCaller(ThisAddIn.Outlook,folderID);
}
testCaller.Run();
}
//Ribbon end
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;
namespace TestNS
{
public class TestCaller{
private Outlook.Application application;
private BackgroundWorker worker = new BackgroundWorker();
private Test test = null;
private string folderId;
private bool init = true;
private bool busy = false;
public TestCaller(Outlook.Application application, string folderId){
this.application = application;
this.folderId = folderId;
worker.DoWork += new DoWorkEventHandler(DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(OnCompleted);
}
public void Run()
{
if (!busy)
{
busy = true;
test = new Test(application, folderId, init);
worker.RunWorkerAsync();
}
}
private void DoWork(object sender, DoWorkEventArgs e)
{
test.Process();
test = null;
}
private void OnCompleted(object sender, RunWorkerCompletedEventArgs e)
{
busy = false;
init = false;
}
}
class Test
{
public const string key_preCreateProperty ="preCreate";
public const string key_postCreateProperty = "postCreate";
private Outlook.Application application;
private string folderId;
private bool createData;
public Test(Outlook.Application application,string folderId,bool createData)
{
this.application = application;
this.folderId = folderId;
this.createData = createData;
}
public void Process(){
Examine();
if(createData){
CreateData();
}
}
public void CreateData()
{
List<Poco> pocos = new List<Poco>();
for (int i = 0; i < 10; i++)
{
pocos.Add(
new Poco
{
Pre = "Pre" + i,
Post = "Post" + i
}
);
}
CreateContactItems(folderId,pocos);
}
public void Examine()
{
bool preIsLoaded = false;
bool postIsLoaded = false;
Debug.WriteLine(">>>Examine");
Outlook.MAPIFolder folder = application.Session.GetFolderFromID(folderId);
Outlook.Items folderItems = folder.Items;
int i = 0;
//print UserProperties registered to the items
foreach(Outlook.ContactItem contactItem in folderItems){
var itemUserProperties = contactItem.UserProperties;
string itemUserPropertiesString = "";
foreach (var itemProp in itemUserProperties)
{
Outlook.UserProperty prop = (Outlook.UserProperty)itemProp;
itemUserPropertiesString += " " +prop.Name + " " + prop.Value + " \n";
}
//HERE: sometimes it prints only Pre on the first index of the iteration
Debug.WriteLine(string.Format("i={0} , itemUserProperties Count={1} , following UserProperties: \n{2}", i++, itemUserProperties.Count, itemUserPropertiesString));
string pre = null;
string post = null;
try
{
pre = contactItem.GetUserProperty(key_preCreateProperty);
preIsLoaded = true;
}
catch(KeyNotFoundException ex){
Debug.WriteLine("Error: Pre Not found"); //should not happen - doesn't happen
}
try
{
post = contactItem.GetUserProperty(key_postCreateProperty);
postIsLoaded = true;
}
catch (KeyNotFoundException ex)
{
Debug.WriteLine("Error: Post Not found"); //shoul not happen - happens rarely totally indeterminitic
}
Marshal.ReleaseComObject(itemUserProperties);
}
Debug.WriteLine("<<<Examine");
if (folderItems.Count > 0 && (!preIsLoaded || !postIsLoaded))
{
MessageBox.Show("preIsLoaded="+preIsLoaded +" \n" +"postIsLoaded="+postIsLoaded);
}
Marshal.ReleaseComObject(folderItems);
Marshal.ReleaseComObject(folder);
}
public void CreateContactItems(string folderId,List<Poco> pocos)
{
Outlook.MAPIFolder folder = application.Session.GetFolderFromID(folderId);
foreach(Poco poco in pocos){
CreateContactItem(folder,poco);
}
Marshal.ReleaseComObject(folder);
}
public void CreateContactItem(Outlook.MAPIFolder testFolder,Poco data)
{
Outlook.ContactItem contactItem = application.CreateItem(Outlook.OlItemType.olContactItem);
contactItem.SetUserProperty(key_preCreateProperty, data.Pre);
contactItem.Save();
Outlook.ContactItem movedContactItem = (Outlook.ContactItem)contactItem.Move(testFolder);
Marshal.ReleaseComObject(contactItem);
contactItem = movedContactItem;
contactItem.FirstName = data.Pre;
contactItem.LastName = data.Post;
contactItem.SetUserProperty(key_postCreateProperty, data.Post);
contactItem.Save();
Marshal.ReleaseComObject(contactItem);
}
}
public static class Util
{
public static void SetUserProperty(this Outlook.ContactItem item, string name, dynamic value)
{
Outlook.UserProperty property = item.UserProperties[name];
if (property == null)
{
property = item.UserProperties.Add(name, Outlook.OlUserPropertyType.olText);
}
property.Value = value;
}
public static dynamic GetUserProperty(this Outlook.ContactItem item, string name)
{
Outlook.UserProperty property = item.UserProperties[name];
if (property != null)
{
return property.Value;
}
throw new KeyNotFoundException(string.Format("UserProperty name={0} not found", name));
}
}
public class Poco
{
public string Pre
{
get;
set;
}
public string Post
{
get;
set;
}
}
}
Thank you for any replies
Outlook Object Model cannot be used on a secondary thread within a COM addin. Outlook 2016 will raise an exception as soon as it detects an OOM object being accessed on a secondary thread.

EWS streaming notifications not received

Afternoon all,
I have a windows service which subscribes to an Office365 email account and awaits new emails, when they arrive it processes their attachments, and all is well with the world.
But... for some reason, the applications stops receiving notifications after an undetermined amount of time.
I have handled the 'OnDisconnect' event and reestablish a connection as shown in the below code, but that doesnt seem to be fixing this issue. The windows service continues to run fine, and if I restart the service everything is good again, until is failed again.
This is the my class for running exchange:
public class ExchangeConnection
{
static readonly ExchangeService Service = Exchange.Service.ConnectToService(UserDataFromConsole.GetUserData(), new TraceListener());
public event EmailReceivedHandler OnEmailReceived;
public ExchangeConnection()
{
}
public void Open()
{
SetStreamingNotifications(Service);
var signal = new AutoResetEvent(false);
signal.WaitOne();
}
private void SetStreamingNotifications(ExchangeService service)
{
var streamingsubscription = service.SubscribeToStreamingNotifications(new FolderId[] { WellKnownFolderName.Inbox }, EventType.NewMail);
var connection = new StreamingSubscriptionConnection(service, 30);
connection.AddSubscription(streamingsubscription);
connection.OnNotificationEvent += OnEvent;
connection.OnSubscriptionError += OnError;
connection.OnDisconnect += OnDisconnect;
connection.Open();
}
public void MoveEmail(ItemId id, String folderName = "Archived Emails")
{
var rootFolder = Folder.Bind(Service, WellKnownFolderName.Inbox);
var archivedFolder = rootFolder.FindFolders(new FolderView(100)).FirstOrDefault(x => x.DisplayName == folderName);
if (archivedFolder == null)
{
archivedFolder = new Folder(Service) { DisplayName = folderName };
archivedFolder.Save(WellKnownFolderName.Inbox);
}
Service.MoveItems(new List<ItemId> {id}, archivedFolder.Id);
}
#region events
private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
{
//The connection is disconnected every 30minutes, and we are unable to override this,
//so when we get disconnected we just need to reconnect again.
var connection = (StreamingSubscriptionConnection)sender;
connection.Open();
}
private void OnEvent(object sender, NotificationEventArgs args)
{
var subscription = args.Subscription;
// Loop through all item-related events.
foreach (var notification in args.Events)
{
switch (notification.EventType)
{
case EventType.NewMail:
if (notification is ItemEvent)
{
var email = Item.Bind(Service, new ItemId(((ItemEvent) notification).ItemId.UniqueId));
OnEmailReceived(new EmailReceivedArgs((EmailMessage)email));
}
break;
}
}
}
private void OnError(object sender, SubscriptionErrorEventArgs args)
{
var e = args.Exception;
Logger.LogException(e,LogEventType.Error);
}
#endregion events
}
Any help would be great, thanks.
EDIT:
After improving the error logging I have found this exception occuring:
Exception: The specified subscription was not found.
Any ideas what is causing this?
With Office365 you need to make sure you deal with affinity see http://msdn.microsoft.com/en-us/library/office/dn458789(v=exchg.150).aspx . Adding those headers will ensure your requests will always routed to the correct servers.
Cheers
Glen

Categories