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

Free Support Forum - aspose.com

okCopying emails from old exchnage to new one

strong text
I need to connect to my old Exchange server and retrieve list of emails based on certain criteria (send/receive date) then export these emails to a new Exchange server , can this be done through Aspose.Emails?

@osmansays,

You may use the code snippet given below to transfer messages from one exchange server to another.

string mailboxUri = "https://outlook.office365.com/EWS/Exchange.asmx";
string domain = @"";
string username = @"Email1";
string password = @"Password1";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);

ExchangeQueryBuilder builder = new ExchangeQueryBuilder();

// Set Emails Date Filter
builder.InternalDate.Since(DateTime.Now.AddDays(-7));

MailQuery query = builder.GetQuery();

ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri, query);

List<MailMessage> messages = new List<MailMessage>();
int i = 1;
foreach (ExchangeMessageInfo msgInfo in msgCollection)
{
    MailMessage msg = client.FetchMessage(msgInfo.UniqueUri);
    messages.Add(msg);
    i++;
}
client.Dispose();
                
username = @"Email2";
password = @"Password2"; 
credentials = new NetworkCredential(username, password, domain);
client = EWSClient.GetEWSClient(mailboxUri, credentials);
client.AppendMessages(messages);
client.Dispose();

Please visit the link given below to get additional information regarding the criteria to filter messages.
Message filtering criteria.
We Hope that this answered your question. Please feel free to reach us if additional information is required.