Page 1 of 1

c# webapi, i can't read mails following codes, exception

Posted: 2020-05-05 13:52
by mekola
Hi, i am developing c# web api for reading all mails and read mail according to id.
I'm following COM API documentary but i can't figure out one thing.

In Messages sections, there is ItemByDBID but i can't use it properly.

this is my simple code:

Code: Select all

        public IEnumerable<MailModel> Get(int id)
        {
            hMailServer.ApplicationClass application = new hMailServer.ApplicationClass();
            application.Authenticate("Administrator", "password");
            hMailServer.Domain domain = application.Domains.ItemByName["domain.com"];
            hMailServer.Accounts accounts = domain.Accounts;
            hMailServer.Account mailbox = accounts.ItemByAddress["some@domain.com"];
            hMailServer.IMAPFolders imapFolders = mailbox.IMAPFolders;
            hMailServer.IMAPFolder imapfolder = imapFolders.ItemByName["INBOX"];
            hMailServer.Messages messages = imapfolder.Messages;
            List<MailModel> mailmodels = new List<MailModel>();
            for (int i = 0; i< messages.Count; i++)
            {
                hMailServer.Message message = messages.ItemByDBID[i];  // EXCEPTION
                mailmodels.Add(new MailModel() { numberId = message.ID, Subject = message.Subject,BodyText=message.Body,From=message.From  });
            }        
            return mailmodels;
        }
>>hMailServer.Message message = messages.ItemByDBID;
Gives me: System.Runtime.InteropServices.COMException: 'Invalid directory. (HRESULT returned an exception: 0x8002000B (DISP_E_BADINDEX))

For example, i can get number of mails properly with messages.Count but i can not figure out ItemByDBID :(
I want to just, it gives me all mail in JSON type.
Sorry my bad english.
Please, thank you su much

Re: c# webapi, i can't read mails following codes, exception

Posted: 2020-05-05 15:53
by SorenR
DBID is the not per account - it is the entire database table...

Code: Select all

hMailServer.Message message = messages.Item[i];
is probably the one you want.

You can learn a lot from this script

https://www.hmailserver.com/forum/viewt ... 52#p175052

Re: c# webapi, i can't read mails following codes, exception

Posted: 2020-05-05 16:30
by mekola
Thanks your reply so much.
I search retry and i find this,

in C# COM API hmail References => There is no " Item", just there is "ItemDBID" ( i also search object browser)

in VB COM API hmail References = Yes there is an Item as documantation

i think there is no same Item issue in C# than
i will try same thing in VB, and i will reply again.

Thank you

Re: c# webapi, i can't read mails following codes, exception

Posted: 2020-05-05 17:12
by SorenR
mekola wrote:
2020-05-05 16:30
Thanks your reply so much.
I search retry and i find this,

in C# COM API hmail References => There is no " Item", just there is "ItemDBID" ( i also search object browser)

in VB COM API hmail References = Yes there is an Item as documantation

i think there is no same Item issue in C# than
i will try same thing in VB, and i will reply again.

Thank you
U r joking... no?

Re: c# webapi, i can't read mails following codes, exception

Posted: 2020-05-05 17:14
by mekola
I tried in VB and it works fine
Thank you
Now i have to convert all of C# codes to VB, i think

i guess there is no another way because C# has not Item object in messages.

thanks your advices again, god bless you.

you answered when writing these articles.

Really in C# Hmailserver References, there is no Item object

Re: c# webapi, i can't read mails following codes, exception

Posted: 2020-05-05 17:39
by mekola
in C#
i upload as images.
i hope external link is not a reason for punishment.

For C#,

https://ibb.co/GJstJdM

For VB,

https://ibb.co/QQmp0HM

edit: in C# this(int) NOT shown as such messages.this

Re: c# webapi, i can't read mails following codes, exception

Posted: 2020-05-05 18:17
by SorenR
mekola wrote:
2020-05-05 17:39
in C#
i upload as images.
i hope external link is not a reason for punishment.

For C#,

https://ibb.co/GJstJdM

For VB,

https://ibb.co/QQmp0HM
Weird... I'm going to dig in the hMailAdmin code (C#) to see how lists are made... It'll be the same with Rules, Domains, Accounts etc...

Re: c# webapi, i can't read mails following codes, exception

Posted: 2020-05-05 18:43
by SorenR

Re: c# webapi, i can't read mails following codes, exception

Posted: 2020-05-17 01:51
by mekola
SorenR wrote:
2020-05-05 18:43
Found something here...

https://www.hmailserver.com/forum/viewt ... 02#p197802
I don't know how to thank you,
I have been trying for this for days.
Thank you so much. :) :)