bvstone

G4MSMAIL Updated to Allow Use Of Configuration Files and More

Posted:

G4MSMAIL Updated to Allow Use Of Configuration Files and More

New Configuration Files

As with MAILTOOL Plus, we have just updated G4MSMAIL so that you are able to use JSON configuration files to set the value of certain options that are static.

When the latest version of G4MS is installed you will get a new file in the IFS named:

/bvstools/g4ms/config/defaults.json

This file will contain all the available parameters that you can use.  Following is an example:

{
	"variables": [
	{
		"name":"id",
		"default":" "
	},
	{
		"name":"from",
		"default":" "
	},
	{
		"name":"from_name",
		"default":" "
	},
	{
		"name":"sender",
		"default":" "
	},
	{
		"name":"sender_name",
		"default":" "
	},
	{
		"name":"subject",
		"default":" "
	},
	{
		"name":"message",
		"default":" "
	}, 
	{
		"name":"message_stream_file",
		"default":" "
	},
	{
		"name":"parent_folder",
		"default":" "
	},
	{
		"name":"label_id",
		"default":" "
	},
	{
		"name":"message_id",
		"default":" "
	},
	{
		"name":"attachment_id",
		"default":" "
	},
	{
		"name":"attachment_name",
		"default":" "
	},
	{
		"name":"get_new_only",
		"default":"*YES"
	},
	{
		"name":"mark_as_read",
		"default":"*YES"
	},
	{
		"name":"move_to_folder",
		"default":" "
	},
	{
		"name":"max_part_size",
		"default":"16773104"
	},
	{
		"name":"get_parts",
		"default":" "
	},
	{
		"name":"message_content_type",
		"default":" "
	},
	{
		"name":"message_importance",
		"default":"Normal"
	},
	{
		"name":"deliver_receipt_requested",
		"default":"false"
	},
	{
		"name":"read_receipt_requested",
		"default":"false"
	},
	{
		"name":"save_to_sent_items",
		"default":"true"
	},
	{
		"name":"no_attachment_action",
		"default":" "
	},
	{
		"name":"temp_dir",
		"default":"/tmp"
	},
	{
		"name":"reset",
		"default":"*YES"
	},
	{
		"name":"ccsid",
		"default":"1208"
	},
	{
		"name":"debug",
		"default":"*NO "
	},
	{
		"name":"debug_file",
		"default":" "
	},
	{
		"name":"dump_file",
		"default":" "
	}	
  ]
}

Any parameters that are specified in the configuration file that is used will override those use previously with the MAILTOOL command.

If you are using the G4MSMAIL subprocedures then the order that you set values and load defaults using the #g4msmail_loadDefaults() function will determine which value is used in the end.

Following is an example program:

     H DFTACTGRP(*NO) ACTGRP('G4MS') BNDDIR('G4MS')
      ****************************************************************
      * Imports
      ****************************************************************
      /COPY QCOPYSRC,P.G4MSMAIL
      ****************************************************************
     D CRLF            C                   CONST(X'0D25')
      *
     D rc              S             10i 0
     D errorMsg        S            256
     D displayErr      S             52
      ****************************************************************
      /free

       rc = #g4msmail_init();
       rc = #g4msmail_setValue('configuration_file':'*DFT');
       rc = #g4msmail_loadDefaults();

       if (rc < 0);
         #g4msmail_dumpSettings(); // This will make a json file with settings and values
       else;
         rc = #g4msmail_addRecipient('bvstone@gmail.com':'Brad@Gmail':g4ms_TO);
         rc = #g4msmail_setValue('subject':'Hello there!');
         rc = #g4msmail_setValue('message':'*STMF');
         rc = #g4msmail_setValue('message_stream_file':'/tmp/test.txt');

         rc = #g4msmail_sendMail(g4ms_uniqueID:errorMsg);

         if (rc < 0);
           #g4msmail_dumpSettings(); // This will make a json file with settings and values
           displayErr = errorMsg;
           DSPLY displayErr;
         endif;

       endif;

       EXSR $return;
       //***************************************************************
       //* Return
       //***************************************************************
       begsr $return;

         *INLR = *ON;
         return;

       endsr;
      /end-free

You will notice that the configuration file is *DFT.  This special value will first look for a configuration file named /bvstools/g4ms/config/<userid>/defaults.json where "<userid>" is the user id of the person running the application.

Instead of *DFT you can also specify the fully qualified path to the configuration file you wish to use.

New Functions

Three new functions are also available with G4MS.

#g4msmail_init() - This is used to initialize everything before running the application.  This isn't required to be used, but it is a good idea to use it if you want all the default values set before you continue with your application.

#g4msmail_loadDefaults() - As mentioned previously, this function is used to set values from a configuration file.  The configuration file is set using the #g4msmail_setValue('configuration_file':<config>') command.

#g4msmail_dumpSettings() - This function is used to dump the settings for your application.  Should G4MSMAIL encounter an error sending the email, this function is automatically called so that along with debug files, the settings used will also be available.


Last edited 01/16/2017 at 16:21:17




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