We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Threading EWS impersonation

I'm developing an application to archive emails and I'm using the following code to get the messages from Exchange online. The code works fine until I thread the application and impersonate more than two users. It works doing multiple threads impersonating one user. Each thread has it's own instance of IEWSclient.

This is the Error:
Cannot get message item and Mime Content ErrorAccessDenied
Access is denied. Check credentials and try again., Cannot get ID from name. validUser@validSite.com

Is this possible or is there a setting or something that I'm missing to allow impersonation of multiple users on different threads?
// Get document content
public bool getDocumentContent(object oclient, string eid, Stream save,string impersonatedUser, bool impersonate, StringBuilder err)
IEWSClient client = (IEWSClient)oclient;
if (impersonate)
client.ImpersonateUser(ItemChoice.PrimarySmtpAddress, impersonatedUser);
string id = suUtil.parseElementShortId(eid);
MailMessage msg = client.FetchMessage(id);
msg.Save(save, SaveOptions.DefaultMsg);
return true;
catch (Exception ex)
err.Append(ex.Message + " " + impersonatedUser);
return false;

Hi Dan,

Thank you for writing to Aspose Support team.

We have checked the available documentation and also confirmed from our Product team about this issue. There is no other setting that should be used to allow impersonation of multiple users on different threads.

Can you please share your server details and runnable code sample with us that you are using at your end? Also, specify the exact scenario with us if you are impersonating the same user in parallel or using different users?