****************************************
      * Program name: mail.cbl
      * This program provides several examples
      * of email statement usage.
      *
      * Copyright 2000 Deskware, Inc.
      ****************************************                                                                                                        
      *                                                               
      * Include the TCP/IP variable copybook.
       COPY `tcpip.cpy`.
       
      * Program Variables
       1 to_address      PIC X(30).
       1 from_address    PIC X(30).
       1 subject         PIC X(40).
       1 message.
          5 message_text1   PIC X(100).

       1 email_address   PIC X(30).
       1 email_password  PIC X(30).
       1 email_count     PIC 9(05).
       1 email_number    PIC 9(05).
       1 email_filename PIC X(20).
       1 smtp_server PIC X(40).
       1 pop3_server PIC X(40).

      * Substitute your information in for the literals below       
       MOVE `email@yourdomain.com`         TO to_address. 
       MOVE `test@yourdomain.com`          TO from_address.
       MOVE `mail.cbl test`                TO subject.
       MOVE `This is a test from mail.cbl` TO message.
       MOVE `your.smtp.com`                TO smtp_server.
       
       IF from_address(1:4) = `test`
          DISPLAY `Edit this program's email variables to run it.`
          GOBACK
       ELSE
          PERFORM PROCESS-SENDMAIL
       END-IF.

      * Substitute your information in for the literals below  
       MOVE `you@yourdomain.com` TO email_address.
       MOVE `password`           TO email_password.
       MOVE 0                    TO email_count.
       MOVE `yoursmtpserver.com` TO pop3_server.

       IF email_address(1:3) = `you`
          DISPLAY `Edit this program's email variables to run it.`
          GOBACK
       ELSE
          PERFORM PROCESS-GETMAIL
       END-IF.

       GOBACK.


      *******************************
      * PROCESS-SENDMAIL paragraph
      *******************************
       PROCESS-SENDMAIL.
           SENDMAIL USING to_address
                          from_address
                          subject
                          message
                         smtp_server.

           DISPLAY `TCPIP-RETURN-CODES: ` & TCPIP-RETURN-CODES.

      ********************************
      * PROCESS-GETMAIL paragraph
      ********************************
       PROCESS-GETMAIL.              
          GETMAILCOUNT USING email_address
                          email_password
                          email_count
                          pop3_server.
      
          DISPLAY `email_count: `  & email_count.
          DISPLAY `TCPIP-RETURN-CODES: `  & TCPIP-RETURN-CODES.
      
          IF email_count IS GREATER THAN 0 THEN
      *      Substitute your information in for the literals below  
             MOVE `you@yourdomain.com` TO email_address
             MOVE `password` TO email_password
             MOVE 1 TO email_number
             MOVE `mymail.txt` TO email_filename
             MOVE `yoursmtpserver.com` TO pop3_server

             IF email_address(1:3) = `you`
                DISPLAY `Edit this program's email variables to run it.`
                GOBACK
             ELSE
                GETMAIL USING email_address
                              email_password
                              email_number
                              email_filename
                              pop3_server
                DISPLAY `TCPIP-RETURN-CODES: `  & TCPIP-RETURN-CODES
             END-IF
          END-IF.