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:

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