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

Free Support Forum - aspose.com

Access "Sent Items" for different Exchange accounts?

Hi.

I am looking at the Aspose.Email .NET component for our in-house applications. What I need to do is to have an automated program send out mails for different users as the sender through Exchange 2010 using EWS. I have an Exchange account set up with the required rights.

Each message should, however, not be stored in the Sent Items Folder of the account I use to log in, but rather in the Sent Items Folder of the user in whose name it was sent.

Is that possible?

Hi Gerhard,

Thank you for using Aspose.Email for .NET.

Well, for this purpose you need to impersonate your account to the other account through which you want to send the email, otherwise it won’t appear in the sent items of the other folder. Please have a look at the code sample below that shows how to do this and let us know your feedback.

Sample Code:

IEWSClient client1 = EWSClient.GetEWSClient(“https:[//outlook.office365.com/ews/exchange.asmx](https://outlook.office365.com/ews/exchange.asmx)”, "UserOne@ASE1982.onmicrosoft.com", “pwd”, “”);

IEWSClient client2 = EWSClient.GetEWSClient(“https:[//outlook.office365.com/ews/exchange.asmx](https://outlook.office365.com/ews/exchange.asmx)”, "UserTwo@ASE1982.onmicrosoft.com", “pwd”, “”);

client1.ImpersonateUser(ItemChoice.PrimarySmtpAddress, "UserTwo@ASE1982.onmicrosoft.com");

MailMessage eml = new MailMessage("UserTwo@ASE1982.onmicrosoft.com", "recepient@gmail.com", “Test Subject”, “Test Body”);

client1.Send(eml);

client1.ResetImpersonation();

Dear Kashif,

thank you for the reply. Your example what require the Password for the invidual user account, which can not be know to the central, automated program.

I am rather using one special account with Receive-As and Send-As rights to all relevant user accounts. Any chance with that?

Thank You!
Gerd

Hi Gerhard,

The above code sample relies on the fact that both the UserOne and UserTwo accounts have been configured to allow impersonation. In the code sample, the usage of Password is required for Client1 only to connect to the Exchange Server using EWS. Client2 is not used in this code sample. Thus, the email is sent as if it was sent by UserTwo and the sent mail is added to the Sent Items folder. There is no other method available further that can be used to get what you are aiming at. Please let us know if we can be of any additional help to you.