Chapter 3 - MAILTOOL ILE Fuctions
MAILTOOL includes a set of ILE functions so that you can send emails easily from within a program without needing to use the QCmdExc API. The available functions are as follows:
mailtool_init - Initialize the email fuction
mailtool_setValue - Set the value of a parameter
mailtool_setUserHeader - Set the values for a user header and value.
mailtool_setMsgPtr - Set the value of the message using a pointer
mailtool_loadDefaults - Load the defaults values form the currently set configuration file
mailtool_addRecipient - Add a recipient to the email
mailtool_addTORecipient - Add a recipient of type "TO"
mailtool_addCCRecipient - Add a recipient of type "CC"
mailtool_addBCCRecipient - Add a recipient of type "BCC"
mailtool_addAttachment - Add an attachment to the email
mailtool_clearRecipients - Clear the entire recipient list, or clear only a specific type of recipient (TO, CC or BCC)
mailtool_sendMail - Send the email!
An example program that would send a simple email would look like the following:
****************************************************************
* Imports
****************************************************************
/COPY QCOPYSRC,P.MAILTOOL
****************************************************************
D rc S 10i 0
D errMsg S 256
********************************************************************
/free
if (mailtool_init() >= 0);
rc = mailtool_setValue('configuration_file':<your config file>);
rc = mailtool_loadDefaults();
rc = #mailtool_setValue('from_email':'jimmyj@repsolracing.com');
rc = mailtool_setValue('subject':'test email');
rc = mailtool_setValue('message':'this is the message \n\n newline.');
rc = mailtool_addTORecipient('mybrother@outlook.com');
rc = mailtool_addCCRecipient('mysister@gmail.com');
rc = mailtool_addBCCRecipient('govtspy@us.gov');
rc = mailtool_sendMail(errMsg);
endif;
*INLR = *ON;
/end-free
If you wanted to replace the IBM QtmmSendMail API and use MAILTOOL Plus, instead of calling the IBM API you could easily use the ILE functions as such, since your MIME file should already be created.
****************************************************************
* Imports
****************************************************************
/COPY QCOPYSRC,P.MAILTOOL
****************************************************************
D rc S 10i 0
D errMsg S 256
********************************************************************
/free
// perform all the same things you did before here, creating the MIME
// file and getting a list of recipients. Then instead of a call to
// QtmmSendMail, do the following:
if (mailtool_init() >= 0);
rc = mailtool_setValue('configuration_file':<your config file>);
rc = mailtool_loadDefaults();
rc = mailtool_setValue('mime_file':<your mime file>);
// must add at least one recipient
rc = mailtool_addTORecipient('mybrother@outlook.com');
// optional to add the from address, subject and message if they're
// not in the config file or you want to override the values
rc = mailtool_setValue('from_email':'jimmyj@repsolracing.com');
rc = mailtool_setValue('subject':'test email');
rc = mailtool_setValue('message':'this is the message \n\n newline.');
// optional to set any other values or override values from the config file
rc = mailtool_setValue('debug':'*YES');
// send the email
rc = mailtool_sendMail(errMsg);
endif;
*INLR = *ON;
/end-free