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!

For most people, they will only use certain information in the configuration file, for example just the information for the mail router and credentials:

{
	"variables": [
    {
		"name":"from_email",
		"default":"bvstone@bvstools.onmicrosoft.com"
	},
	{
		"name":"from_name",
		"default":"Brad Stone @ Office 365"
	},
	{
		"name":"send_with_server_type",
		"default":"*MAILTOOL"
	},
	{
		"name":"mail_router",
		"default":"smtp.office365.com"
	},
	{
		"name":"use_mail_router",
		"default":"*ONLY"
	},
	{
		"name":"use_ssl",
		"default":"*TLS"
	},
	{
		"name":"smtp_port",
		"default":"587"
	},
	{
		"name":"smtp_auth_user",
		"default":"bvstone@bvstools.onmicrosoft.com"
	},
	{
		"name":"smtp_auth_password",
		"default":"mypassword"
	}	]
}


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 12/17/2020 at 11:02:13



Latest Posts:

SSL Handshake Errors with GETURI, MAILTOOL and GreenTools Products SSL Handshake Errors with GETURI, MAILTOOL and GreenTools Products
Posted by October 18, 2021
BVSTools >> BVSTools Software Discussion
MAILTOOL Updated to Retry Sending when GSK SSL Handshake Error 415 (GSK_ERROR_BAD_PEER) is Encountered MAILTOOL Updated to Retry Sending when GSK SSL Handshake Error 415 (GSK_ERROR_BAD_PEER) is Encountered
Posted by August 19, 2021
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
MAILTOOL Updated to Allow List-Unsubscribe and User Defined Headers MAILTOOL Updated to Allow List-Unsubscribe and User Defined Headers
Posted by August 13, 2021
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
AWS signing process in as400 AWS signing process in as400
Posted by August 13, 2021
Programming >> Web Programming
2022 License Price Increase and Consulting Update for Non-Software Specific Assistance 2022 License Price Increase and Consulting Update for Non-Software Specific Assistance
Posted by August 9, 2021
BVSTools >> BVSTools Announcements
Journaling the IFS, SPLTOOL and Java Journaling the IFS, SPLTOOL and Java
Posted by August 4, 2021
BVSTools >> BVSTools Announcements >> Spooled File Tools (SPLTOOL) Specific Announcements
G4MSMAIL Now Allows Wildcard Attachments G4MSMAIL Now Allows Wildcard Attachments
Posted by June 10, 2021
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
G4G Update for Uploading Large Files G4G Update for Uploading Large Files
Posted by May 28, 2021
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
Can We Purchase License Keys for More Than One Year at a Time? Can We Purchase License Keys for More Than One Year at a Time?
Posted by May 21, 2021
BVSTools >> BVSTools Announcements
JOBWATCH 5.10 Released with New Feature to Monitor CPU Percentages JOBWATCH 5.10 Released with New Feature to Monitor CPU Percentages
Posted by May 10, 2021
BVSTools >> BVSTools Announcements >> Job Watch (JOBWATCH) Specific Announcements
Iseries Access data transfer Iseries Access data transfer
Posted by April 29, 2021
IBM Power Systems >> (QGPL) IBM i
YAJL - Parsing YAJL - Parsing
Posted by April 4, 2021
Programming >> RPG Programming
Create LPAR partition and install OS Create LPAR partition and install OS
Posted by March 24, 2021
IBM Power Systems >> (QGPL) IBM i
G4MS Now Allows User/Password Authentication Option G4MS Now Allows User/Password Authentication Option
Posted by March 16, 2021
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
IPDS printer file using CHRSIZ IPDS printer file using CHRSIZ
Posted by February 25, 2021
Programming >> RPG Programming

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).