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');
    rc = mailtool_sendMail();  

    if (rc < 0);
      //handle error
    endif; 

  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');                      
    rc = mailtool_sendMail();

    if (rc < 0);
      //handle error
    endif; 
   
  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 10/10/2022 at 11:57:16



Latest Posts:

Microsoft Office 365 Servers and Random Errors Issue Microsoft Office 365 Servers and Random Errors Issue
Posted by November 14, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Sending/Resending Emails Using a MIME File with MAILTOOL Sending/Resending Emails Using a MIME File with MAILTOOL
Posted by November 8, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Sending an HTML Email on Your IBM i Using MAILTOOL Sending an HTML Email on Your IBM i Using MAILTOOL
Posted by November 1, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Transferring License Keys from One System to Another Transferring License Keys from One System to Another
Posted by October 31, 2022
BVSTools >> BVSTools Software Discussion
Calculating the Size of a File Before Base64 Encoding Calculating the Size of a File Before Base64 Encoding
Posted by August 13, 2022
Programming >> RPG Programming
GreenTools for Microsoft Apps (G4MS) v9.12 Now Includes Function to Send Emails using MIME File GreenTools for Microsoft Apps (G4MS) v9.12 Now Includes Function to Send Emails using MIME File
Posted by August 11, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
GreenTools for Google Apps (G4G) v15.20 Now Supports Shortcuts GreenTools for Google Apps (G4G) v15.20 Now Supports Shortcuts
Posted by August 6, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools for Microsoft Apps (G4MS) Groups Admin Authority Instructions GreenTools for Microsoft Apps (G4MS) Groups Admin Authority Instructions
Posted by July 26, 2022
BVSTools >> BVSTools Software Discussion >> GreenTools for Microsoft Apps (G4MS) Specific Discussion
GreenTools for Microsoft Apps (G4MS) v9.10 Now Includes OneDrive Functions that Work With Groups/Shared Drives GreenTools for Microsoft Apps (G4MS) v9.10 Now Includes OneDrive Functions that Work With Groups/Shared Drives
Posted by July 19, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
GreenTools for Google Apps (G4G) v15.10 Now Includes Drive Functions that Work With Shared Drives GreenTools for Google Apps (G4G) v15.10 Now Includes Drive Functions that Work With Shared Drives
Posted by July 15, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page
Posted by July 4, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
What Objects Should I Omit from Replication to Ensure My License Keys Work on my HA/DR System? What Objects Should I Omit from Replication to Ensure My License Keys Work on my HA/DR System?
Posted by June 27, 2022
BVSTools >> BVSTools Software Discussion
GreenTools for Google Apps (G4G) v15.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page GreenTools for Google Apps (G4G) v15.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page
Posted by May 3, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
How Do I Switch From MAILTOOL Plus to GreenTools for Google (OAuth 2.0) or Microsoft Office 365? How Do I Switch From MAILTOOL Plus to GreenTools for Google (OAuth 2.0) or Microsoft Office 365?
Posted by April 18, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
PTFs Issued for SSL/TLS Issues PTFs Issued for SSL/TLS Issues
Posted by March 12, 2022
IBM Power Systems >> PTF Watch

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