bvstone

MAILTOOL v7 Integrates Easy to use ILE Functions and Configuration Files - Send Email from your IBM i (AS/400)

Posted:

MAILTOOL v7 Integrates Easy to use ILE Functions and Configuration Files - Send Email from your IBM i (AS/400)

The latest update to our MAILTOOL Software includes two major updates to make the software even more functional as useful:

ILE Functions
MAILTOOL now has ILE functions available that make sending emails from ILE Programs simple, compared to the past when building a command and calling QCMDEXC was required.  This means sending an email is as simple as the following few lines of code:

 /COPY QCOPYSRC,P.MAILTOOL                                                   

 /free
  if (#mailtool_init() >= 0);   
    #mailtool_setValue('from_email':'publisher@booksrus.com'); 
    #mailtool_setValue('subject':'test email');
    #mailtool_setValue('message':'this is the message nn newline.');  
    #mailtool_addTORecipient('james@thegiantpeach.com'); 
    #mailtool_addAttachment('/myfiles/pdfs/salesreport.pdf');
    #mailtool_sendMail();   
  endif;                
                        
  *INLR = *ON;          
                        
 /end-free 

See this article if you're needing assistance compiling your program to use the F.MAILTOOL ILE Service Program.

 

Configuration Files
Configuration Files are now used to set the values of most parameters and values of a MAILTOOL call, either from the command (when *DFT or a configuration file is specified) or from the ILE functions (when a configuration file is specified).

When using the MAILTOOL command and specifying *DFT for the configuration file the file that is used will be /bvstools/mailtool/config/userid/defaults.json (where userid is the user's User ID).  If this file doesn't exist, then the supplied default configuration file /bvstools/mailtool/config/defaults.json will be used.

This can be used to set default values such as the mail server to use, the FROM address, subject, as well as a host of other values.  

The configuration files are standard JSON files so a simple text editor is all that is needed to change the values.

When using the MAILTOOL command you can also override all the parameters (except for the TO, CC, BCC, Subject, Message and Attachment parameters) by specifying a configuration file to use on the MAILTOOL command.  

MAILTOOL TOADDR('bvstone@bvstools.com') 
SUBJECT('Testing config file') 
MESSAGE('This is a test of the config file') 
CONFIG('/bvstools/mailtool/config/myconfig.json')

The From address, as well as any other parameters (such as SENDWITH, MAILRTR, USERTR, SSL, DEBUG, etc) will use the values in the Configuration file specified. 

If a configuration file is used with the MAILTOOL command, the parameters on the MAILTOOL command will be overridden with the values from the configuration file EXCEPT for the recipients (TO, CC and BCC) and Attachments or if the value of the default is blank or doesn't exist in the configuration file used.

This ability has also been added to the SPL2EMAIL and SPL2EMAILB commands for compatibility.

Configuration Files can also be used in the ILE functions.  The only difference is any of the values that once the #mailtool_loadDefaults() function is called any values in the configuration file will override any values already set by #mailtool_setValue().  The opposite is also true, so be sure to do things in the correct order for your project.

 /COPY QCOPYSRC,P.MAILTOOL                                                   

 /free                                                                       
  if (#mailtool_init() >= 0);                                                
    #mailtool_setValue('configuration_file':'/bvstools/mailtool/config/myconfig.json');
    #mailtool_loadDefaults();
    #mailtool_addTORecipient('james@thegiantpeach.com');                      
    #mailtool_sendMail();   
  endif;                
                        
  *INLR = *ON;          
                        
 /end-free 

In this example the only value we are setting is the TO address.  Everything else, including the FROM address, Subject and Message are set using the values in the configuration file.

So, what does one of these configuration files look like?  Here's an example of the one that is shipped with MAILTOOL:

{
	"variables": [
	{
		"name":"from_email",
		"default":" "
	},
	{
		"name":"from_name",
		"default":" "
	},
	{
		"name":"subject",
		"default":" "
	},
	{
		"name":"message",
		"default":" "
	},
	{
		"name":"reply_to_email",
		"default":" "
	},
	{
		"name":"reply_to_name",
		"default":" "
	},
	{
		"name":"mdn_email",
		"default":" "
	},
	{
		"name":"mdn_name",
		"default":" "
	},
	{
		"name":"sender_email",
		"default":" "
	},
	{
		"name":"sender_name",
		"default":" "
	},
	{
		"name":"footer_stream_file",
		"default":" "
	},
	{
		"name":"message_id",
		"default":" "
	},
	{
		"name":"message_id_domain",
		"default":" "
	},
	{
		"name":"send_with_server_type",
		"default":"*IBMSMTP"
	},
	{
		"name":"mail_router",
		"default":"*NONE"
	},
	{
		"name":"use_mail_router",
		"default":"*NO"
	},
	{
		"name":"perform_mx_lookup",
		"default":"*YES"
	},
	{
		"name":"use_ssl",
		"default":"*NO"
	},
	{
		"name":"smtp_port",
		"default":"25"
	},
	{
		"name":"smtp_auth_user",
		"default":" "
	},
	{
		"name":"smtp_auth_password",
		"default":" "
	},
	{
		"name":"bind_to_ip_address",
		"default":" "
	},
	{
		"name":"timeout",
		"default":"30"
	},
	{
		"name":"ccsid",
		"default":"819"
	},
	{
		"name":"no_attachment_action",
		"default":" "
	},
	{
		"name":"body_content_type",
		"default":"text/plain"
	},
	{
		"name":"mime_ccsid",
		"default":"819"
	},
	{
		"name":"temporary_directory",
		"default":"/tmp"
	},
	{
		"name":"importance",
		"default":"normal"
	},
	{
		"name":"priority",
		"default":" "
	},
	{
		"name":"recipient_separator",
		"default":","
	},
	{
		"name":"close_connection",
		"default":"*YES"
	},
	{
		"name":"save_email",
		"default":"*DFT"
	},
	{
		"name":"debug",
		"default":"*NO"
	},
	{
		"name":"debug_file",
		"default":"mailtooldebug_/%id%/.txt"
	},
	{
		"name":"debug_smtp_file",
		"default":"mailtoolsmtp_/%id%/.txt"
	}
	]
}

As you can see, the values are simple name/value pairs that can be easily edited and copied!

More information can be found in the MAILTOOL documentation at http://docs.bvstools.com.

MAILTOOL can be downloaded from http://www.bvstools.com/mailtool.html


Last edited 08/20/2015 at 15:08:40



Latest Posts:

MAILTOOL Updated to Allow G4GSMAIL as Option in Routers File MAILTOOL Updated to Allow G4GSMAIL as Option in Routers File
Posted by 3 days ago
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
BVSTools Now Offers Interface with Infor's ION APIs BVSTools Now Offers Interface with Infor's ION APIs
Posted by May 15, 2020
BVSTools >> BVSTools Announcements
More V7R4 IFS File CCSID Issues and The Fix More V7R4 IFS File CCSID Issues and The Fix
Posted by March 4, 2020
IBM Power Systems >> (QGPL) IBM i
Error Retrieving IP Address by Name Error Retrieving IP Address by Name
Posted by February 25, 2020
BVSTools >> BVSTools Software Discussion
Logging jobs that hit an outq Logging jobs that hit an outq
Posted by February 13, 2020
Programming >> CL Programming
GreenTools for Google Apps (G4G) v12.60 Released with Shared Drive Features and More... GreenTools for Google Apps (G4G) v12.60 Released with Shared Drive Features and More...
Posted by February 4, 2020
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
Allowing Requests over Port 80 For SSL Validation (ie, Namecheap, etc) Allowing Requests over Port 80 For SSL Validation (ie, Namecheap, etc)
Posted by January 31, 2020
Programming >> Web Programming
GreenTools for Slack (G4SLK) v3.00 Released GreenTools for Slack (G4SLK) v3.00 Released
Posted by January 17, 2020
BVSTools >> BVSTools Announcements >> GreenTools for Slack (G4SLK) Specific Announcements
Calling a QSH Command from RPG Calling a QSH Command from RPG
Posted by December 26, 2019
Programming >> RPG Programming
SPLTOOL Print Range (PRTRNG) Function Updated to Handle Spooled Files up to 999,999,999 Pages SPLTOOL Print Range (PRTRNG) Function Updated to Handle Spooled Files up to 999,999,999 Pages
Posted by December 14, 2019
BVSTools >> BVSTools Announcements >> Spooled File Tools (SPLTOOL) Specific Announcements
GreenTools for Microsoft Apps (G4MS) Updated to v6.00 - Now Uses Microsoft Graph APIs GreenTools for Microsoft Apps (G4MS) Updated to v6.00 - Now Uses Microsoft Graph APIs
Posted by November 24, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
V7R4 Changes CCSID of Compressed File Using PASE JAR Command - Here's The Fix V7R4 Changes CCSID of Compressed File Using PASE JAR Command - Here's The Fix
Posted by November 21, 2019
IBM Power Systems >> (QGPL) IBM i
Using GETURI to Make OAuth 2.0 Requests - Custom Headers for Access Tokens Using GETURI to Make OAuth 2.0 Requests - Custom Headers for Access Tokens
Posted by November 11, 2019
BVSTools >> BVSTools Software Discussion >> Get URI (GETURI) Specific Discussion
GreenTools for Microsoft Apps (G4MS) v5.00 Released with Updated OneDrive Support and 3rd Party Functionality GreenTools for Microsoft Apps (G4MS) v5.00 Released with Updated OneDrive Support and 3rd Party Functionality
Posted by October 20, 2019
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
BVSTools is Now Running V7R4M0 BVSTools is Now Running V7R4M0
Posted by September 28, 2019
BVSTools >> BVSTools Announcements

Reply




Copyright 1983-2020 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).