We have some customers that like to write their own programs to resend emails when they error out and being sent with MAILTOOL.
Normally I share this code snippet with them to help them get going. It's part of the code that is used in the MTPLUSLOG and MTPRESEND commands used to resend emails using the MAILTOOL Plus log files.
I hope this helps some customers.
if (emailID > 0); // emailID is the mail ID from the log files CHAIN emailID MTPLOGH1; if (%found(MTPLOGH1)); if (mailtool_init() >= 0); rc = mailtool_setValue('configuration_file':MPHCONFIG); rc = mailtool_loadDefaults(); rc = mailtool_setValue('mime_file':MPHMIME); SETLL WFID MTPLOGD1; READE(n) WFID MTPLOGD1; // add recipients dow (not %eof(MTPLOGD1)); mailtool_addRecipient(MPDRCP:' ':MPDRCPT); READE(n) WFID MTPLOGD1; enddo; rc = mailtool_sendMail(errMsg); if (rc < 0); // error - this will add a new entry to the error logs // so deleting the log records below won't have duplicate // errors if this fails. else; // success endif; // delete header record DELETE RMTPLOGH; // delete detail records SETLL WFID MTPLOGD1; READE WFID MTPLOGD1; dow (not %eof(MTPLOGD1)); DELETE RMTPLOGD; READE WFID MTPLOGD1; enddo; endif; endif; else; // error invalid email ID endif;
The file operations would most likely be SQL if I were to write this today, and there should also be more error checking (for example, checking to make sure the MIME and JSON configuration files exist) but for the most part this should be 90% of the process required to make your own email resending application.
As always, feel free to contact us with any questions.