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

Free Support Forum - aspose.com

Importing from filesystem to exchnage public folder

Hi, I am trying to import from a filling folder that contains deep multi folder paths containg eml doc/xls/pdf files. (The files exceed 260 length)
How can I import them in an exchange public folder? I can iterate through my filesystem but I am unsure how to create folder and subfolders in exchange and also how to add the non eml files such as pdf doc etc.
Thanks for your help.

Hi Lesley,

Thank you for contacting Aspose support.

We can add the public folder as shown in the following sample code.

public static IEWSClient GetAsposeEWSClientTest3()

{

const string mailboxUri = “https:[//exchange.domain.com/ews/Exchange.asmx](https://exchange.domain.com/ews/Exchange.asmx)”;

const string domain = @"";

const string username = @“username”;

const string password = @“password”;

NetworkCredential credentials = new NetworkCredential(username, password, domain);

IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);

return client;

}

static void Email_574436()

{

string folderName = “NETWORKNET_28016_email”;

ExchangeFolderInfo rootPublicFolder = null;

IEWSClient client = GetAsposeEWSClientTest3();

ExchangeFolderInfoCollection folders = client.ListPublicFolders();

foreach (ExchangeFolderInfo folderInfo in folders)

if (folderInfo.DisplayName.Equals(“root”))

rootPublicFolder = folderInfo;

folders = client.ListSubFolders(rootPublicFolder.Uri);

foreach (ExchangeFolderInfo folderInfo in folders)

if (folderInfo.DisplayName.Equals(folderName))

{

[//TestUtil.CleanFolder](https://testutil.cleanfolder/)(client, folderInfo.Uri);

client.DeleteFolder(folderInfo.Uri, true);

}

client.CreateFolder(rootPublicFolder.Uri, folderName);

}

Regarding adding the files, I have tried to drop the .doc/.xls files into exchange inbox however it opens the new message window where dropped file is present as attachment. Thus you may please create a simple message with subject as the name of dropped file and append this message (using AppendMessage func) to the target public folder. If this does not fulfill your requirement, please write us back along with more details. We will try to provide assistance as soon as possible.

Hi, thanks for your prompt reply. I created the required folders in the exchange Public folder, however the messages that I append are in draft mode, that is they are ready to be sent…
sample of my code below,
string folderName = “TestFolder”;
client.CreateFolder(rootPublicFolder.Uri, folderName);
MailMessage message1 = MailMessage.Load(“c:\test.msg”, MessageFormat.Msg);
client.AppendMessage(rootPublicFolder.Uri, message1);

Please advise…
Thanks
Lesley

Hi Lesley,


Could you please try the following overload of AppendMessage where markAsSent flag can be set and let us know the feedback?


string AppendMessage(string folder, MailMessage message, bool markAsSent);

Hi, again, the markAsSent (true) was the answer, thanks, however immediately another problem cropped up, the date that appears on the email in outlook is todays date, and not of the received time of the message which was a year ago… This is critical as we lose track of message reception date.
Please advise.
Thanks
Lesley

Hi Lesley,

Thank you for sharing your concern with us.

I was able to reproduce this issue at my end using the latest version of Aspose.Email for .NET 4.5.0 and have logged it as NETWORKNET-34504 in our issue tracking system for further investigation by our development team. Once there is any information available in this regard, I'll update you here via this thread.

We are sorry for the inconvenience caused to you.

Hi Lesley,

We have analyzed the problem and have observed that Aspose.Email sets proper date as set by the user while message is appended to exchange inbox.

You may please give a try to the following sample code where message is appended to inbox and then retrieved again. It can be seen that same date is present in the retrieved message as set by the user. Also an image is attached which shows the user defined date when this message is opened using Outlook.

using (IEWSClient client = GetAsposeEWSClient1())
{
try
{
MailMessage message = new MailMessage(
"user1@domain.com",
"user2@domain.com",
"AE 4.5 EMAIL_574436 - " + Guid.NewGuid().ToString(),
“AE 4.5 EMAIL_574436 AppendMessage() to EWS changes the message date to current date”);
message.Date = new DateTime(2010, 1, 1, 9, 0, 0);
string uri = client.AppendMessage(client.MailboxInfo.InboxUri, message,true);
MailMessage fetchedMessage = client.FetchMessage(uri);
TimeSpan timeZoneShift = message.Date - fetchedMessage.Date;
message.Date = new DateTime(2008, 2, 1, 10, 0, 0);
uri = client.AppendMessage(client.MailboxInfo.InboxUri, message, true);
fetchedMessage = client.FetchMessage(uri);
[//Assert.IsNotNull](https://assert.isnotnull/)(fetchedMessage);
[//Assert.AreEqual](https://assert.areequal/)(message.Date - timeZoneShift, fetchedMessage.Date);
}
finally
{
[//TestUtil.CleanFolder](https://testutil.cleanfolder/)(client);
}
}

Hi Kashif,
Thanks for your reply,
Pls note that your answer does not apply to my problem
My problem was with the wrong date, while inserting messages from the filesystem in to public folders, and not new message in the INBOX.
If you read the mails in the thread, you will see that you confirmed this problem
Thanks
Lesley

Hi Lesley,

I have tried the same scenario with public folder as well and observed that old date of message is retrieved after fetching the message from the public folder. The sample code used for this testing is given below along with the sample output of the program. The only difference in time is the zone offset but that is in number of hours.

Could you please give it a try and let us know the feedback?

IEWSClient _client = EWSClient.GetEWSClient(“https:[//outlook.office365.com/ews/exchange.asmx](https://outlook.office365.com/ews/exchange.asmx)”, "user@mail.onmicrosoft.com", “password”, “”);
ExchangeFolderInfoCollection folders = _client.ListPublicFolders();
MailMessage message = MailMessage.Load(@“D:\aspose\OldMessage.msg”);
string uri = _client.AppendMessage(folders[0].Uri, message, true);
MailMessage fetchedMessage = _client.FetchMessage(uri);
TimeSpan timeZoneShift = message.Date - fetchedMessage.Date;
Console.WriteLine(“Actual Message Date:” + message.Date);
Console.WriteLine(“Fetched Message Date:” + fetchedMessage.Date);
Console.WriteLine(“Offset difference (Hours):” + timeZoneShift.Hours);