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

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
mekola
New user
New user
Posts: 7
Joined: 2020-05-05 13:36

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

Post by mekola » 2020-05-05 13:52

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

User avatar
SorenR
Senior user
Senior user
Posts: 4201
Joined: 2006-08-21 15:38
Location: Denmark

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

Post by SorenR » 2020-05-05 15:53

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
SørenR.

Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.

mekola
New user
New user
Posts: 7
Joined: 2020-05-05 13:36

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

Post by mekola » 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

User avatar
SorenR
Senior user
Senior user
Posts: 4201
Joined: 2006-08-21 15:38
Location: Denmark

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

Post by SorenR » 2020-05-05 17:12

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?
SørenR.

Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.

mekola
New user
New user
Posts: 7
Joined: 2020-05-05 13:36

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

Post by mekola » 2020-05-05 17:14

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

mekola
New user
New user
Posts: 7
Joined: 2020-05-05 13:36

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

Post by mekola » 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

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

User avatar
SorenR
Senior user
Senior user
Posts: 4201
Joined: 2006-08-21 15:38
Location: Denmark

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

Post by SorenR » 2020-05-05 18:17

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...
SørenR.

Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.

User avatar
SorenR
Senior user
Senior user
Posts: 4201
Joined: 2006-08-21 15:38
Location: Denmark

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

Post by SorenR » 2020-05-05 18:43

SørenR.

Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.

mekola
New user
New user
Posts: 7
Joined: 2020-05-05 13:36

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

Post by mekola » 2020-05-17 01:51

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. :) :)


Last bumped by mekola on 2020-05-17 01:51.

Post Reply