EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Retrieving From/To/CC/BCC from Mailheader

Posted: 01/15/2013 06:54:03
by Anton Kufer (Standard support level)
Joined: 12/18/2012
Posts: 16

i'm still having troubles to get mails from a mailserver. works fine using indy, but with eldos i'm again stuck.

after connecting to the server i go through the list of mails. per mail i retrieve the headers to scan through the fields.

the iteration via getfield() works as planned, but "MailAddressListCount" does always return 0, so i can't go through the adresses as you describe using "GetMailAddressList". see the code below.

the getfield list correctly includes from/to/cc/bcc, but the adresslist seems to be empty?

can you tell me what i am doing wrong?

i'm deerly missing a straightforward example of retrieving mails without that complicated tree overhead with makes pulling out the code even more timeconsuming.

such a small yet comprehensive example would be very much appreciated!


//  t_POP3.GetMailboxInfo(t_Count, t_Size);
    t_Anzahl := t_POP3.GetMessageCount;
    MessageDlg(IntToStr(t_Anzahl)+' eMails auf dem Konto',mtInformation,[mbOK],0);

    for i := 0 to Length(t_MessageIDs)-1 do
        t_Index := t_MessageIDs[i].Index;

        if t_POP3.ReceiveMessageHeader(t_Index, t_Charset, true, t_Header)=EL_OK then
          for j := 0 to pred(t_Header.FieldsCount) do
            t_HeaderField := t_Header.GetField(j);
            t_Str := '';
            t_Str := str_paste(t_Str,'Name -> '+t_HeaderField.Name,#13#10);
            t_Str := str_paste(t_Str,'Value -> '+t_HeaderField.Value,#13#10);
            t_Str := str_paste(t_Str,'Body -> '+t_HeaderField.Body,#13#10);
            t_Str := str_paste(t_Str,'Comments -> '+t_HeaderField.Comments,#13#10);

//        t_Size := t_POP3.GetMessageSize(t_Index);
          t_MessageID := t_POP3.GetMessageID(t_Index);

          Self.MailMessage.ID := i;
          Self.MailMessage.UID := t_MessageID;
          Self.MailMessage.MsgId := trim(t_Header.GetField('message-id').Value);

          Self.MailMessage.IsAnmeldung := false;

          Self.MailMessage.AdrFrom := '';
          for j := 0 to pred(t_Header.MailAddressListCount) do
            if t_Header.GetMailAddressList(j)<>nil then
              t_MailAddressList := t_Header.GetMailAddressList(j);
              for k := 0 to pred(t_MailAddressList.Count) do
                t_MailAddress := t_MailAddressList.GetAddress(k);
                Self.MailMessage.AdrFrom := str_paste(Self.MailMessage.AdrFrom,t_MailAddressList.FieldName+' -> '+trim(t_MailAddress.Address),' #;# ');
Posted: 01/15/2013 07:15:40
by Vsevolod Ievgiienko (Team)

Thank you for contacting us.

Could you download a full message and try to load it using \EldoS\SecureBlackbox.VCL\Samples\Delphi\MIMEBlackbox\Viewer sample. Does the sample also return zero addresses? You can put a breakpoint in ElMimeViewer_MainForm.pas:TfrmMain.TreeViewExpanding method to check this or simply check the result in the treeview. If the problem still exists then please post the message via Helpdesk and we'll use it to reproduce the problem. If not then please compare your code to the sample.
Posted: 01/15/2013 07:35:33
by Anton Kufer (Standard support level)
Joined: 12/18/2012
Posts: 16

the viewer works, it displayes the content correctly. but, as said, i tried to compare the code, but i can't find the problem. the viewer is so overloaded with code, i couldn't find the problem there.

to me it seems it works with a elmessagepart thing, but that doesn't apply to a header?

you may check my code, that should be pretty straightforward.

it's just a plain TElPOP3Client component. do i need to apply anything to something somewhere? i just don't know.

the message should look something like this attached. but it's a different message. atleast the headers should be something like this.
Posted: 01/15/2013 08:21:48
by Anton Kufer (Standard support level)
Joined: 12/18/2012
Posts: 16

i now tried



  t_MessagePart := t_Message.MainPart.GetPart(j);

but nothing works.

the example to me seems the same.
Posted: 01/15/2013 08:24:23
by Vsevolod Ievgiienko (Team)

We'll check the problem and will write you back.
Posted: 01/16/2013 01:32:31
by Anton Kufer (Standard support level)
Joined: 12/18/2012
Posts: 16

any new information on this?
Posted: 01/16/2013 03:42:57
by Alexander Ionov (Team)

We've checked the issue. This is by design.

If you work ONLY with message header, you're responsible to process header fields in the way you need them. So in order to get mail addreses fields parsed, you should use TElMessageHeader.FieldCount property and TElMessageHeader.GetField method to iterate through all the header fields. You can use SBMIME.IsMailAddressField(FieldName) to determine which header field is a mail address field. Then you should create an instance of TElMailAddress list and call its Parse method passing TElMessageHeaderField.Body property value to it.

This is done this way because on automatic parsing the mail address fields are delete from the general fields list and moved to another list. This makes difference for those who need the header fields in the original order.

If you have an instance of TElMessage class, then the address header fields are parsed automatically only when you attempt to access TElMessage.From, TElMessage.To_, etc. properties.

Best regards,
Alexander Ionov



Topic viewed 937 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!