Return Email sent

hello,

how can I return the emails they are already sent from Exchange ?

best regards,

Nacata

Hi Nacata,


Thank you for writing to Aspose support team.

Could you please elaborate your requirements for our further investigation? We’ll look into it as soon as possible and assist you further.

Hello,

if I want to retrieve the received emails I use "ExchangeMessageInfo" and "MailMessage" now I want to retrieve the emails sent from my mailbox
what can I use?

Regards,

Nacata

Hi Nacata,

The code sample will remain the same with only one change i.e. you will have to use the Sent Items URI instead of Inbox URI as shown in the following code sample. Please let us know if we can be of any additional help to you in this regard.

Sample Code:

ExchangeMessageInfoCollection coll = client.ListMessages(client.MailboxInfo.SentItemsUri);

foreach (ExchangeMessageInfo msgInfo in coll)
{
    MailMessage msg = client.FetchMessage(msgInfo.UniqueUri);
    msg.Save(msg.Subject + ".eml", MailMessageSaveType.EmlFormat);
}

Hello,
thank you.
I have another question : how can i return the sent and the received emails from my exchange in the the same time ?

Regards
NACATA

Hi Nacata,

It is not possible to retrieve both type of messages from different folders at a same time. You may perform this task using the following sample code where first the sent messages are extracted and then unread messages from the inbox are retrieved.

public static IEWSClient GetAsposeEWSClient()
{
const string mailboxUri = “https:[//exchange.domain.com/ews/Exchange.asmx](https://exchange.domain.com/ews/Exchange.asmx)”;
const string domain = @"";
const string username = @“user”;
const string password = @“password”;
NetworkCredential credentials = new NetworkCredential(username, password, domain);
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);
return client;
}

public static void TestSentReceived()
{
using (IEWSClient client = GetAsposeEWSClient())
{
ExchangeMessageInfoCollection coll = client.ListMessages(client.MailboxInfo.SentItemsUri);
foreach (ExchangeMessageInfo msgInfo in coll)
{
MailMessage msg = client.FetchMessage(msgInfo.UniqueUri);
//Process mail
}

ExchangeListMessagesOptions options = new ExchangeListMessagesOptions();
ExchangeQueryBuilder builder1 = new ExchangeQueryBuilder();
builder1.HasNoFlags(ExchangeMessageFlag.IsRead);
MailQuery query = builder1.GetQuery();
ExchangeMessageInfoCollection UnreadMsgCollection = client.ListMessages(client.MailboxInfo.InboxUri, query, false);
foreach (Aspose.Email.Exchange.ExchangeMessageInfo msgInfo in UnreadMsgCollection)
{
Aspose.Email.Mail.MailMessage MailMsg = client.FetchMessage(msgInfo.UniqueUri);
//Process message
}
}
}

Please feel free to write us back for any further queries.