You can use the following RPG sample program to read all email messages from a POP3 account, call the program POPEX003C, and then call POPEX003R to process each line of the email message. You can write custom logic in POPEX003R to parse the email-message text. 
 
Prerequisite: POP/400 version 1.10 or above.
 

Calling POPGET and POPEX003C/POPEX003R for Each Downloaded Message

To connect to a POP3 server, retrieve all messages, and then process them with program POPEX003C, run the following commands:
 
Note: This example does not delete the messages after downloading, but in production you should do so. 
  1. ADDLIBLE RJSPOP3
  2. POPGET POP3HOST('1.1.1.1') USER('test@yourcompany.com') PASSWORD('test')
  3. GETMSGHDRS(*YES) GETMESSAGE(*YES) DELETEMSG(*YES) LOGSESSION(*YES) 
  4. DSPSESSION(*YES) EXITPGM RJSPOP3/POPEX003C)                                                   

Sample CL Program - POPEX003C

 /********************************************************************/
/* This is a sample exit program that is called directly after a    */
/* new message is created from the POPGET command.                  */
/*                                                                  */
/* Parm 1: AS/400 Message File                                      */
/* Parm 2: AS/400 Message File Library                              */
/* Parm 3: AS/400 Message File Mamber                               */
/* Parm 4: Email Message Date  (Date:)                              */
/* Parm 5: Email Message Author (From:)                             */
/* Parm 6: Email Message Recip (To:)                                */
/* Parm 7: Email Message Subject (Subject:)                         */
/********************************************************************/
        PGM        PARM(&IFILE &ILIB &IMBR &IDATE &IFROM &ITO +  
                     &ISUBJECT)                                  
                                                                 
/* DECLARE PARAMETERS */     

        DCL        VAR(&IFILE) TYPE(*CHAR) LEN(10)               
        DCL        VAR(&ILIB) TYPE(*CHAR) LEN(10)                
        DCL        VAR(&IMBR) TYPE(*CHAR) LEN(10)                
        DCL        VAR(&IDATE) TYPE(*CHAR) LEN(100)              
        DCL        VAR(&IFROM) TYPE(*CHAR) LEN(150)              
        DCL        VAR(&ITO) TYPE(*CHAR) LEN(150)                
        DCL        VAR(&ISUBJECT) TYPE(*CHAR) LEN(150)           
                                                                 
        MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ERRORS))      
                                                                 
/***************************************************************/     
/* DO SOME PROCESSING                                          */     
/* OUR SAMPLE SIMPLY SENDS BACK INFO MESSAGES TO THE JOB LOG   */     
/***************************************************************/     
        OVRDBF     FILE(POPMSG) TOFILE(&ILIB/&IFILE) MBR(&IMBR)  
        CALL       PGM(POPEX003R)                                
        DLTOVR     FILE(POPMSG)                                  

                                                                  
/***************************************************************/     
/* REMOVE MEMBER IF YOU DON'T WANT TO KEEP IT                  */     
/***************************************************************/     
/**            RMVM       FILE(&ILIB/&IFILE) MBR(&IMBR)     ****/     
                                                                 
/***************************************************************/     
/* NORMAL END OF PROCESSING                                    */     
/***************************************************************/     
        RETURN                                                   
                                                                 
/***************************************************************/     
/* HANDLE ERRORS                                               */     
/***************************************************************/     
ERRORS:                                                               
                                                                 
/* SEND EXIT MESSAGE ON ERROR */                                   
        SNDPGMMSG  MSGID(POP9898) MSGF(POPMSGF) MSGDTA('Errors + 
                     occurred during POP/400 exit point +        
                     message processing for msg Member:' | 0                        
 C                   Eval      StartInput = 1                           
 C                   Endif                                              
                                                                 
 C                   ENDIF                                              
                                                                   
 C                   ENDDO                                              
                                                                   
 C                   Eval      *INLR = *ON                              
 C                   RETURN                                             

 


Still have questions? We can help. Submit a case to Technical Support.

Last Modified On: December 10, 2016