bvstone

Using a Stream File as the Message Body of an Email Using MAILTOOL or G4MS ILE Subprocedures

Posted:

Using a Stream File as the Message Body of an Email Using MAILTOOL or G4MS ILE Subprocedures

I was recently asked what would be the proper way to send an email using an existing HTML document (which resides in the IFS) as the body of an email.

This can be done with a command, or the ILE subprocedures included in MAILTOOL.  

Using the MAILTOOL command you will specify the following:

MAILTOOL TOADDR(toaddress@domain.com) SUBJECT('This is my subject') MESSAGE(*ATT) ATTACH('/myifs/files/filename.ext')    

When you specify *ATT for the message, that tells MAILTOOL to use the first attachment listed as the body of the email.  All following attachments listed will be treated as normal attachments.

If the file you are using is HTML, be sure to specify Body Content Type (BDYCT) parameter as text/html.                                

Using the MAILTOOL ILE subprocedures it would look like the following:

// init and set other values

fileName = '/tmp/docs/letter.html';  //This should be the fully qualified path to the file
rc = mailtool_setValue('message':'*ATT');                     
rc = mailtool_setValue('body_content_type':'text/html');      
rc = mailtool_addAttachment(fileName);       

// send the email

If you are using the G4MSMAIL addon to G4MS, your code would look like this:

This should be all you need.

// init and set other values

fileName = '/tmp/docs/letter.html'; //This should be the fully qualified path to the file
rc = g4msmail_setValue('message':'*STMF');                      
rc = g4msmail_setValue('message_stream_file':fileName); 
rc = g4msmail_setValue('message_content_type':'html');

// send the email

As always, feel free to contact us with any questions.


Last edited 03/16/2022 at 12:09:25




Reply




© Copyright 1983-2024 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).