Partner400 Logo
    RPGMail
   

 

This is the version of the RPGMail routine published in the October 2004 issue of the eServer magazine, iSeries edition. For the fixed form version click here.


  All About Us

  Where To See Us

  Magazine Articles

  Downloads

  Rational RDi

  On-site Training

  The RPG Redbook

  Home Page

 

 

 

 

 

 

 

 

 

 



      //*********************************************************************
//
// Send Invoice via Email (c)Copyright Partner400, 2004.
//
// This sample program is provided for illustration purposes only and
// is provided "AS IS". The implied warranties of merchantability and
// fitness for a particular purpose are expressly disclaimed.
//
// Before you can compile and run this program, you will need to:
// a) Download and install the MMAIL utility
// - download at www-922.ibm.com
//
// b) Create the CSTMAST file.
// - It must contain at least the following fields:
//
// CUSTNO CHAR 6 Customer Number
// CONTACT CHAR 15 Contact Name
// EMAIL CHAR 50 E-Mail Address
//
//*********************************************************************

/copy MMAIL/qrpglesrc,hspecsbnd

H DftActGrp(*No) Option(*SrcStmt : *NoDebugIO)

FCstMast IF E K Disk

/copy MMAIL/qrpglesrc,mailproto

D FromName S 50A Inz('Susan Gantner')
D FromEmail S 50A Inz('Contact@partner400.com')
D SenderEmail S 255A Inz('Contact@partner400.com')
D EmailTemplate s 512A Inz('/Partner400/invMime.txt')
D InvPDFFile S 512A

D ToNameArr S 50A dim(1000)
D ToAddrArr S 256A dim(1000)
D ToDistArr S 10I 0 dim(1000)
D ContType S 21A Inz('application/pdf')
D BinFlag S 1A Inz('Y')
D ImbAtt S 10I 0 Inz(2)

D TempFile s 512A
D Error s 7A

D Reply S 1

D TxtVarArr s 10A DIM(500)
D TxtValArr s 500A DIM(500)

D Today S D

D SndInv PR ExtPgm('SNDINV')
D InvPDF 25A Const
D Customer Like(CustNo)

D SndInv PI
D InvPDF 25A Const
D Customer Like(CustNo)

//=====================================================================
// Main line
//=====================================================================

/FREE

InvPDFFile = InvPDF;
Chain(E) Customer CstMast;
If Not %Error and %Found(CstMast);

If Email <> ' ';

// Create email Temporary file in the IFS for the note

TempFile = TempCrtF();

// Add Sender info to the email - includes date and time

MimeSender(TempFile : FromName : FromEmail);

// Receiver name and email from CstMast record added to 1st element of Array

ToNameArr(1)=Contact;
ToAddrArr(1)=Email;
ToDistArr(1)=0;

// Add Receiver info to email Temporary File

MimeDistr(TempFile : ToNameArr:
ToAddrArr : ToDistArr);

// Supply substitution values to replace variables in template file

TxtVarArr(1) = '&Name';
TxtVarArr(2) = '&Date';
TxtValArr(1) = Contact;
Today = %Time();
TxtValArr(2) = %Char(Today);

MimeUpdTxt(TempFile : EmailTemplate:
TxtVarArr : TxtValArr);

// Attach PDF file to email - File name is supplied by parameter

MimeImbAtt(TempFile : InvPDFFile :
ContType : BinFlag : ImbAtt);

MimeClose(TempFile);


// Send the email. If errors occur, field Error will contain CPF message

Error = SendMail(TempFile :
SenderEmail : ToAddrArr : ToDistArr);
EndIf;

EndIf;

If Error <> ' ';
Dsply Error ' ' Reply;
Else;
Dsply 'Sent' ' ' Reply;
EndIf;

*INLR = *On;
Return;

/END-FREE

     
Return to Home Page  

Want more information?
Got a question or comment about the site?
Please feel free to Contact Us at any time.}