IBM Support

Example C Program Using the QTMMSENDMAIL API

Troubleshooting


Problem

This is an example of a C program using the QTMMSENDMAIL API.

Resolving The Problem

This program code is provided "as is" as an example only. IBM makes no warranty, either express or implied, regarding the compilability, executability or suitability of this program in any way.

Example

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <pointer.h>
#include <qusec.h>
#include <qtmmsndm.h>
 typedef _Packed struct Addr {  
        Qtmm_ADDT0100_t Info;
         char            Addr[QTMM_MAX_SMTP_ADDR_LENGTH];
} Addr_t;

 int main(int argc, char* argv[])
 {  
    char Filenm[] ="/mail/text.note";
    char * Filename= Filenm;
    long int Filename_Length=strlen(Filenm);

    char * Originator;
    long int Originator_Length;

  Addr_t Recipient;
    Qtmm_ADDT0100_t * pRecipient=&(Recipient.Info);
    long int Total_Num_Of_Recipients;

    int ierrno;  
    FILE *stream;
    Qus_EC_t                   Snd_Error_Code;
   Qus_EC_t * Error;  /* Error handling uses standard api structure */
 
   Error = &Snd_Error_Code;
   Snd_Error_Code.Bytes_Provided=0;    /* surface errors for now */
    if /* at least 4 parms */(argc > 4) {  
         errno=0;
         stream=fopen(Filenm,"w,ccsid=819,crln=Y");  /* create in ascii */    
         ierrno=errno;  
         fclose(stream);
         stream=fopen(Filenm,"w+,ccsid=37,crln=Y");  /* let Integrated File System convert from ebcdic */  
         Originator = argv[3];                                        /* read in ‘from address’ as 3rd parameter */
         Originator_Length = strlen(argv[3]);

        /* Start writing the note */  
        fprintf(stream,"MIME-Version: 1.0 \n");
        fprintf(stream,"from: %s\n",argv[3]);

        Total_Num_Of_Recipients = 1;
        pRecipient->Addr_Length=strlen(argv[4]);
        memcpy(Recipient.Addr,argv[4],  pRecipient->Addr_Length);       /*read ‘to’ address*/                                                                                
        memcpy(pRecipient->Format_Name,  QTMM_ADDRESS_FMT,  QTMM_FMT_LENGTH);
     pRecipient->Reserved=0;
        pRecipient->Dist_Type = QTMM_DIST_TYPE_NORMAL;                                                                                      
        pRecipient->Next_Addr_Structure_Offset =0; /* only 1 recipient */

        fprintf(stream,"to: %s\n",argv[4]);
        fprintf(stream,"subject: %s\n",argv[1]);                 /* subject */
        fprintf(stream,"Content-Type:  multipart/mixed;");  
        fprintf(stream,"  boundary=\"PART.BOUNDARY.xyz\"\n\n");
        fprintf(stream,"--PART.BOUNDARY.xyz\n");  
        fprintf(stream,"Content-Type: text/plain \n\n");
        fprintf(stream,"%s",argv[2]);                                    /* actual text message */
        fprintf(stream,"\n--PART.BOUNDARY.xyz--\n");
        fclose(stream);

       /* Invoke routine to put SMTP/MIME mail into the framework */                                                                          
   
        QtmmSendMail(Filename,                               &Filename_Length,
                                     Originator,
                                  &Originator_Length,
                                     pRecipient,
                                 &Total_Num_Of_Recipients,
                                    (void*)Error);
       }

[{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"6.1.0"}]

Historical Number

19271416

Document Information

More support for:
IBM i

Software version:
6.1.0

Operating system(s):
IBM i

Document number:
641833

Modified date:
18 December 2019

UID

nas8N1017807

Manage My Notification Subscriptions