Problems with creating a mail item in a public folder exchange 2010

I am creating a mail item in a public folder using the apose email toolkit.
This seems to work perfectly in exchange 2013 but when we upload into exchange 2010 it seems to drop the date and as such all emails then end up with a sent date time as when they were filed rather than when they were sent. Am I missing something or does this command not work in exchange 2010 at all. Any help would be greatly appreciated.

msg.DateTimeSent = m.Date;
msg.ExtendedProperty = new ExtendedPropertyType[1];
msg.ExtendedProperty[0] = type;
ciType.Items.Items = new ItemType[1];
ciType.Items.Items[0] = msg;

CreateItemResponseType response = Global.ExchangeServiceBinding.CreateItem(ciType);

Basically, on 2013 the date sticks and on 2010 it doesn’t.
Many thanks,
Gavin

Hi Peter,

Thank you for contacting Aspose support team.

I have tried to re-produce the scenario using below code, but am afraid I could not succeed as whatever the date was set, same was displayed in the Microsoft Exchange 2010 mail folder.

public static void TestSampleCode()
{
IEWSClient client = GetAsposeEWSClientTest3();
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();

ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.DraftsUri);
MailMessage mail = new MailMessage("asposeemail.test3@aspose.com", "from@domain.com",“subject”, “body”);
mail.Date = new DateTime(2013,8,30);
client.AppendMessage(mailboxInfo.DraftsUri, mail);
MapiMessage mapi = new MapiMessage();
}

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 = @“user”;
const string password = @“password”;
NetworkCredential credentials = new NetworkCredential(username, password, domain);
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials);
return client;
}

As the above sample code fulfills the same purpose, you may please give it a try and let us know your feedback. If you need some additional features regarding above sample code, please write back to us.

P.S. On the other hand, if you still want to use EWS api, you may please try it using MIME.

Thanks,
I’ll give that a try and come back to you.
Gavin

I tried that code and it works (in so much as it creates the email but when you go into the public folder the date for filtering is still todays date.



Are you aware of any exchange settings that may restrict updating that field.



We noticed in the internet header that the date was correct but the date that appears at the side of the email is the current date. I have attached a picture which might allow you to get a better idea of the issue. Many thanks for your help so far.

Hi Peter,


When a message is appended to a mailbox that is not in actuality received at the same mailbox, Exchange account will consider it as a draft email and use the current date time with it. That is the reason that the current date time is shown with it and Outlook shows a warning message that this email has not been sent out yet. Once the draft email is sent out, then the actual date of sending will change as per the sending date.

Hi Kashif,

I think I am asking the wrong question possibly.

If you wanted to move a mail item into a public folder and preserve its properties how would you do that.
Or is it the case that this is impossible in 2010.

Many thanks,

Gavin

Hi Peter,

Thank you for clarification.

I think you are looking for moving an item that you can achieve using the following sample code. Please let us know if you need further assistance in this regard.

Sample Code:

// Create instance of IEWSClient class by giving credentials
IEWSClient client = EWSClient.GetEWSClient("https://exchange.domain.com/ews/exchange.asmx", "username", "******", "");

ExchangeMailboxInfo mailbox = client.GetMailboxInfo();

// List all messages from Inbox folder
Console.WriteLine("Listing all messages from Inbox....");
ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailbox.InboxUri);

foreach (ExchangeMessageInfo msgInfo in msgInfoColl)
{
    //Declare variable for getting specified custom folder uri
    ExchangeFolderInfo subfolderInfo = new ExchangeFolderInfo();

    //Check if specified custom folder exisits
    client.FolderExists(mailbox.RootUri, "T1T", out subfolderInfo);

    if (subfolderInfo != null)
    {
        // Move it
        client.MoveItem(msgInfo.UniqueUri, subfolderInfo.Uri); // EWS
        Console.WriteLine("Message moved...." + msgInfo.Subject);
    }
}