meta data for this page
  •  

Working with POP3 servers

The following is an example of using the Functions for working with POP3 servers:

  execute ibeblock
  as
  begin
    CRLF = ibec_CRLF();
 
    ses = ibec_pop3_OpenSession('Host=mypop3.com; User=iam; Pass=12345');
    try
      --Alternative way to set pop3 session properties:
      --sHost = ibec_pop3_SetProperty(ses, 'Host', 'mypop3.com');
      --sUser = ibec_pop3_SetProperty(ses, 'UserName', 'iam');
      --sPass = ibec_pop3_SetProperty(ses, 'Password', '12345');
      --sPort = ibec_pop3_SetProperty(ses, 'Port', 'pop3');
 
      ibec_Progress('Connecting to mypop3...');
      if (ibec_pop3_ConnectAndAuth(ses)) then
      begin
        ibec_Progress('Retrieving Uidl...');
        Res = ibec_pop3_Uidl(ses);
        sResp = ibec_pop3_GetProperty(ses, 'Uidl');
 
        UidlItems = ibec_Explode(CRLF, sResp);
        foreach (UidlItems as UID key Idx skip nulls) do
        begin
          if (UID = '') then
            Continue;
          UidData = ibec_Explode(' ', UID);
          iMsgNum = ibec_Cast(UidData[0], __typeInteger);
          ibec_Progress('Getting message ' + UidData[1] + '...');
          Res = ibec_pop3_Retr(ses, iMsgNum);
          if (Res) then
          begin
            ibec_ForceDirectories('D:\Mails');
            MsgData = ibec_pop3_GetProperty(ses, 'MsgData');
            ibec_SaveToFile('D:\Mails\' + UidData[1], MsgData, 0);
          end;
        end;
      end;
      ibec_Progress('Quit...');
      ibec_pop3_Quit(ses);
    finally
      ibec_pop3_CloseSession(ses);
    end;
  end;