ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

QtmmSendMail -- API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • QtmmSendMail -- API

    Hi Friends,
    I have a specific query regarding the use of this particular API.
    As I have understood this API supports mail sending to multiple recipients. To achieve the same the offset needs to be set everytime for different users as the email IDs may vary in length. But does it mean that the API needs to be called in a loop, and IFS file needs to be created everytime -- as once the MIME IFS file has been used successfully it is unlinked? What I would like to achieve is creating the MIME IFS file only once and send the same to multiple recipient. A small bit of code will be really appreciated.
    What is the difference between ADDT0100 format and ADDR0100 format? I am unable to find any reference to ADDR0100 format.
    Some insight into this will be very helpful.
    Thanks in advance
    SC

  • #2
    Re: QtmmSendMail -- API

    I havnt tried to email multiple users...but from the API description this is possible.
    Have you attempted to do this yet? What are the errors you are getting when you try? Can we see you code so far?

    thanks
    jamie
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: QtmmSendMail -- API

      example with multiple emails


      written by:
      Jeff Olen is a member of the AS/400 development team at Gauss Interprise,
      a content management software company located in Irvine, California.
      He can be reached by email at jeff.olen@gaussvip.com.

      1. CRTRPGMOD MODULE(library/TESTMAIL) SRCFILE(library/QRPGLESRC)
      2. CRTPGM PGM(library/TESTMAIL) MODULE(library/TESTMAIL) BNDSRVPGM(QTCP/QTMMSNDM)

      PHP Code:

           D
      Prototype for QTMMSENDMAIL API
           D sendmail        PR                  Extproc
      ('QtmmSendMail')
           
      D filename                        *   value
           D nameLen                       10i 0
           D OrigAddr                        
      *   value
           D OrigLen                       10i 0
           D RecipTbl                        
      *   value
           D NbrRecips                     10i 0
           D pErr                            
      *   value
           D
           D
      prototype of function to add recipients
           D AddRecip        PR           280
           D  inetAddr                    256    value
           D  AddrType                      2    value
           D
            
      copy error structure from QSYSINC
           D
      /copy qsysinc/qrpglesrc,qusec
           D Qdata                  17    216
           D
            
      set pointer to Error structure
           D pErr            S               
      *   Inz(%addr(QUSEC))
           
      D
            
      email variables
           D RecipTbl        S          32767a
           D Filename        S            255a
           D inetAddr        S            256a
           D nameLen         S             10i 0
           D OrigAddr        S            256a
           D OrigLen         S             10i 0
           D NbrRecips       S             10i 0
           C
           C
      Initialize Error structure parms
           C                   
      Eval      Qusbavl 0
           C                   
      Eval      Qusbprv 216
           C
           C
      load first recipient into table
           C                   
      Eval      inetAddr 'recip1@domain.com'
           
      C                   Eval      RecipTbl = %trim(Reciptbl) +
           
      C                              %trim(AddRecip(inetAddr:'  '))
           
      C
           C
      load second recipient into table (carbon copy)
           
      C                   Eval      inetAddr 'ccRecip@domain.com'
           
      C                   Eval      RecipTbl = %trim(Reciptbl) +
           
      C                              %trim(AddRecip(inetAddr:'CC'))
           
      C
           C
      load all other info to field to be sent to API
           C                   
      Eval      Filename '/path/filename.txt'
           
      C                   Eval      nameLen = %len(%trim(FileName))

           
      C                   Eval      OrigAddr 'orig@orig_domain.com'
           
      C                   Eval      OrigLen = %len(%trim(OrigAddr))
           
      C
           C
      be sure to set the TOTAL number of recipients
           C                   
      Eval      NbrRecips 2
           C
           C
      Send the email
           C                   Callp     sendmail
      (%addr(filename):namelen:
           
      C                              %addr(Origaddr):origlen:
           
      C                              %addr(RecipTbl):NbrRecips:pErr)
           
      C
           C
      end pgm
           C                   
      Eval      *inlr = *on
           C                   
      Return
           
      C*****************************************************************
           
      CAddRecip - function to add recipient to email
           C
      *****************************************************************
           
      P AddRecip        b
           D AddRecip        PI           280
           D InetAddr                     256    value
           D AddrType                       2    value
            
      Addrtype values
            
      * *blanks normal ("To")
            * 
      'CC' carbon copy
            
      'BC' blind carbon copy
           D
            
      ADDT0100 data structure  - (See IBM Qtmmsendmail docs for
            *  
      details)
           
      D tblWork         DS
           D  NextOffset                    9b 0
           D  AddrLen                       9b 0
           D  AddrFmt                       8
           D  DistType                      9b 0
           D  Resrvd01                      9b 0
           D  DestAddr                    256
           D
           C
           C
      load recipient into structure
           C                   
      Eval      Addrfmt 'ADDT0100'
           
      C                   Eval      Resrvd01 0
           C
           C                   Select
           C
      CC carbon copy
           C                   When      AddrType 
      'CC'
           
      C                   Eval      DistType 1
           C
      BC blind carbon copy
           C                   When      AddrType 
      'BC'
           
      C                   Eval      DistType 2
           C
      all other values will be normal
           C                   Other
           C                   
      Eval      DistType 0
           C
           C                   Endsl
           C
           C                   
      Eval      DestAddr inetAddr
           C                   
      Eval      Addrlen = %len(%trim(DestAddr))

           
      C                   Eval      NextOffset 24 Addrlen
           C
           C
           C                   
      Return    tblwork
           P AddRecip        e 
      PHP Code:
           D*** START HEADER FILE SPECIFICATIONS ****************************
           
      D*
           
      D*Header File NameH/QUSEC
           D
      *
           
      D*Descriptive NameError Code Parameter.
           
      D*
           
      D*5763-SS15722-SS1 (CCopyright IBM Corp19942001.
           D
      *All rights reserved.
           
      D*US Government Users Restricted Rights -
           
      D*Use, duplication or disclosure restricted
           D
      *by GSA ADP Schedule Contract with IBM Corp.
           
      D*
           
      D*Licensed Materials-Property of IBM
           D
      *
           
      D*
           
      D*Description: Include header file for the error code parameter.
           
      D*
           
      D*Header Files IncludedNone.
           
      D*
           
      D*Macros List: None.
           
      D*
           
      D*Structure List: Qus_EC_t
           D
      *             Qus_ERRC0200_t
           D
      *
           
      D*Function Prototype List: None.
           
      D*
           
      D*Change Activity:
           
      D*
           
      D*CFD List:
           
      D*
           
      D*FLAG REASON       LEVEL DATE   PGMR      CHANGE DESCRIPTION
           D
      *---- ------------ ----- ------ --------- ----------------------
           
      D*
           
      D*End CFD List.
           
      D*
           
      D*Additional notes about the Change Activity
           D
      *End Change Activity.
           
      D*** END HEADER FILE SPECIFICATIONS ******************************
           
      D*****************************************************************
           
      D*Record structure for Error Code Parameter
           D
      ****                                                          ***
           
      D*NOTEThe following type definition only defines the fixed
           D
      *   portion of the format.  Varying length field Exception
           D
      *   Data will not be defined here.
           
      D*****************************************************************
           
      DQUSEC            DS
           D
      *                                             Qus EC
           D QUSBPRV                 1      4B 0
           D
      *                                             Bytes Provided
           D QUSBAVL                 5      8B 0
           D
      *                                             Bytes Available
           D QUSEI                   9     15
           D
      *                                             Exception Id
           D QUSERVED               16     16
           D
      *                                             Reserved
           D
      *QUSED01                17     17
           D
      *
           
      D*                                      Varying length
           DQUSC0200         DS
           D
      *                                             Qus ERRC0200
           D QUSK01                  1      4B 0
           D
      *                                             Key
           D QUSBPRV00               5      8B 0
           D
      *                                             Bytes Provided
           D QUSBAVL14               9     12B 0
           D
      *                                             Bytes Available
           D QUSEI00                13     19
           D
      *                                             Exception Id
           D QUSERVED39             20     20
           D
      *                                             Reserved
           D QUSCCSID11             21     24B 0
           D
      *                                             CCSID
           D QUSOED01               25     28B 0
           D
      *                                             Offset Exc Data
           D QUSLED01               29     32B 0
           D
      *                                             Length Exc Data
           D
      *QUSRSV214              33     33
           D
      *                                             Reserved2
           D
      *
           
      D*QUSED02                34     34
           D
      *
           
      D*                                      Varying Length    @B1A

      Attached Files
      Last edited by jamief; November 21, 2006, 08:30 AM. Reason: added copybook and text files
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment


      • #4
        Re: QtmmSendMail -- API

        You don't need to API. you need the Mime & Mial tool.

        "Time passes, but sometimes it beats the <crap> out of you as it goes."

        Comment


        • #5
          Re: QtmmSendMail -- API

          Thanks Jamie for the sample code. I have been successful in using this particular API to send email to one recipient and used similar code logic only. The error I received in CPF3C17. As in sample code a distribution list needs to be populated in the specified format 'ADDT0100'. I suspect, for multiple recipient the above format is getting violated (most probably in populating the Offset value) as a result of which the API returns error (as it is unable to resolve the mail IDs).
          Have a look at the code snippet:
          Code:
          D rrPtr           S               *   Inz(%Addr(DistribL))
          D DistribL        S          32767A   Varying           
          D Recipients      DS                  Inz               
          D  OffSet                        9B 0                   
          D  AddrLen                       9B 0                   
          D  Format                        8                      
          D  DistrType                     9B 0                   
          D  Reserved                      9B 0                   
          D  Address                     256A                     
          ----------------------
          C	1	    Do		10
          C                   Eval      Format  = 'ADDT0100'               
          C                   Eval      DistrType = 0                    
          C                   Eval      Reserved = 0                       
          ** Some code to extract address from a variable
          C                   Eval      Address = Extracted Address                         
          C                   Eval      AddrLen = Address Length
          C                   Eval      OffSet = 24 + AddrLen              
          C                   Eval      DistribL = %Trim(DistribL)+%Trim(Recipients)
          C                   Eval      SavPos = Pos + 1                   
          C                   EndDo                                        
          -------------------------------------
          Let me know if I am missing something? For Email1(28) Offset1(24+28=52), for Email2(17) Offset2(24+17=41) -- Is this correct?

          Comment

          Working...
          X