StoreItem_GetProperty() returning empty for all properties (c#)

Discussion for developers using MailEnable.
Post Reply
Steffp01
Posts: 5
Joined: Tue Dec 19, 2017 4:50 pm

StoreItem_GetProperty() returning empty for all properties (c#)

Post by Steffp01 »

Hi,

I’m trying to access the content of an email via Asp.Net and I cannot seem get a value returned, no matter which property I try.

I’ve got a console app that appears to attach to the ME post office and it looks like it’s opened the mailbox I specify, because the number of messages matches those found when I loop through the messages.

But for every message StoreFolder_FindNextItem() finds, the command StoreItem_GetProperty() always brings back nothing, for any property I try. (ME_ITEM_ID, PR_SUBJECT, PR_BODY, PR_ME_SIZE, PR_ME_FROM, PR_ME_TO)

It’s MailEnable 9, Windows Server 2012. The console App does look like it’s iterating through the messages, but I can not get any information via StoreItem_GetProperty.

Can someone please help?

Thanks!

mkucera
Posts: 5
Joined: Wed Jan 17, 2018 2:50 pm

Re: StoreItem_GetProperty() returning empty for all properties (c#)

Post by mkucera »

Did you get any answer to this? I just submitted a forum post and i think it's this same issue. Only difference i can see is that i'm on Windows 2016. I was on Windows 2008 and it worked great there.

Thanks!
-Mark

Steffp01
Posts: 5
Joined: Tue Dec 19, 2017 4:50 pm

Re: StoreItem_GetProperty() returning empty for all properties (c#)

Post by Steffp01 »

No, I didn't get any reply and the issue is still outstanding as I hit a dead-end and haven't been back to it yet.

Did you have the the code working on Windows 2008 and it stopped when you moved it to 2016? I wonder if it's some permissions thing, then?

Please let me know if you find something!

mkucera
Posts: 5
Joined: Wed Jan 17, 2018 2:50 pm

Re: StoreItem_GetProperty() returning empty for all properties (c#)

Post by mkucera »

Yes, that is correct. it was running fine on Windows 2008. When i moved to 2016, i also upgraded to the latest version but my previous version was only a few releases old, so i don't have any reason to believe that was the problem. I agree it's probably a permissions thing somewhere especially since it returns "" instead of actually generating an error. This ran for nearly a day before the problem was detected. Do we know if MailEnable actually monitors and participates in these forums, or is it only peer support? I'm not an eval customer any more and i use the free version so i have to pay for support tickets (even if it's their bug).

In my situation i only need to read the "ME_ITEM_ID" property, which is the message file name <guid>.mai. Ironically i am able to call StoreFolder_FindFirstItem() successfully. Then i know that a new message has arrived, and i've replaced my old API call to storeMessage.StoreItem_GetProperty("ME_ITEM_ID") with a new function i wrote that uses a System.IO.DirectoryInfo object to read the same "ME_ITEM_ID" string i.e. the filename from the file system. I'm lucky in that all my other API calls are working and i'm really able to just swap out this one one API call and my application is working again.

You might be able to do much the same thing that i'm doing... once i get this file name, i manually read the entire message into a byte[] and then I found a POP3 Mail Library (free) called OpenPop to convert the byte[] to a System.Net.Mail.MailMessage object. This works great and you can access all the properties like the To/From/Subject/Body etc. Take a look at the following and see if it might be of use to you.

Code: Select all


private void DoWork()
{
                MailEnable.Store storeMessage = new MailEnable.Store();
                storeMessage.StoreFolder_Open(ConfigurationManager.AppSettings["PostOfficeName"], "INCOMING", "\\Inbox", storeMessage.MessageClass, 1);

                if (storeMessage.StoreFolder_FindFirstItem() == 1) //do we have any messages in the inbox
                {
                   //yes, at least one message was found.
                    do
                    {
                        //get the message id
                        string messageid = storeMessage.StoreItem_GetProperty("ME_ITEM_ID").ToString(); // <--- THIS DOES NOT WORK IN W2K16!!!
                        if (string.IsNullOrEmpty(messageid))
                        {
                            //we know there must be a message because the initial if statement passed.  This is my workaround for the API call not working correctly...
                            messageid = getFirstMessageID();
                        }

                        //get the message body
                        string text = System.IO.File.ReadAllText(InboxFolder + messageid);
                        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                        Byte[] full_body_bytes = encoding.GetBytes(text);
                        OpenPop.Mime.Message mm = new OpenPop.Mime.Message(full_body_bytes);
                        MailMessage m1 = mm.ToMailMessage();
                        
                        //now using m1 you can access any of the messages properties and maybe you can get what you need without making calls to StoreItem_GetProperty()
                        //
                        //...
                        //
                        
                        //when you are done, delete the message. This ensures i dont process it twice.
                        DeleteSingleMessage(messageid, storeMessage);
                    }
                    while ((storeMessage.StoreFolder_FindNextItem() == 1));
               }
               storeMessage.StoreFolder_FindClose();
               storeMessage.StoreFolder_Close();
}

        private void DeleteSingleMessage(string messageID, MailEnable.Store storeMessage)
        {
                long lResult = 0;
                lResult = storeMessage.StoreFolder_DeleteItem(messageID);
                lResult = storeMessage.StoreFolder_Save();
        }

        private string getFirstMessageID()
        {
          //InboxFolder is a global variable pointing to the location of the Inbox folder on the file system.  
            var sortedFiles = new DirectoryInfo(InboxFolder).GetFiles("*.mai").OrderBy(f => f.CreationTime).ToList();
            if (sortedFiles.Count > 0)
            {
                return sortedFiles[0].Name;
            }
            else
            {
                return "";
            }
        }
                        
All the other API calls that are referenced here work as expected.

HTH
-Mark

Steffp01
Posts: 5
Joined: Tue Dec 19, 2017 4:50 pm

Re: StoreItem_GetProperty() returning empty for all properties (c#)

Post by Steffp01 »

That looks like a potential work-around. Thanks so much for sharing! :)

I don't think MailEnable monitor these forums; my original post was unanswered for 11 months. I tried to get help from them directly, as well, but they just ignored me. I slammed my head against this issue for about 2 weeks before shelving it.

I really appreciate you getting back to me - I shall look at it properly in due course! :)

Post Reply