MAILTOOL has the ability to send emails using a pre-created MIME file. This can be done using MAILTOOL Plus, GreenTools for Google Apps(G4G), or GreenTools for Microsoft Apps (G4MS) using Office 365. Each of these options is slightly different, though, on how it is done.
This option can be useful if you already have a program that uses the system email APIs like QtmmSendMail or other tools where you already have a MIME file created.
Click on one of the following links to take you to a specific example.
When using a MIME file with MAILTOOL Plus, the following items are required:
An example program is as follows:
H DFTACTGRP(*NO) BNDDIR('BVSTOOLS')
****************************************************************
* Prototypes *
****************************************************************
/COPY QCOPYSRC,P.MAILTOOL
****************************************************************
D errMsg S 256 INZ
D rc S 10i 0
D msgid S 13S 0
****************************************************************
/free
if (mailtool_init() >= 0);
rc = mailtool_setValue('configuration_file':'*DFT');
rc = mailtool_loadDefaults(errMsg);
rc = mailtool_addTORecipient('bvstone@bvstools.com');
rc = mailtool_setValue('mime_file':'/tmp/mimetest.txt');
rc = mailtool_sendMail(errMsg:msgid);
endif;
*INLR = *ON;
/end-free
In this example we are loading our mail server settings and FROM email address from our configuration file. In this case we specified *DFT instead of a fully qualified path. See this article for more information on how configuration files are processed using *DFT as the option.
An example configuration file would look like the following:
{
"variables": [
{
"name":"from_email",
"default":"bvstone@gmail.com"
},
{
"name":"from_name",
"default":"Brad Stone"
},
{
"name":"send_with_server_type",
"default":"*MAILTOOL"
},
{
"name":"mail_router",
"default":"smtp.gmail.com"
},
{
"name":"use_mail_router",
"default":"*ONLY"
},
{
"name":"perform_mx_lookup",
"default":"*NO"
},
{
"name":"use_ssl",
"default":"*TLS"
},
{
"name":"smtp_port",
"default":"587"
},
{
"name":"smtp_auth_user",
"default":"bvstone@gmail.com"
},
{
"name":"smtp_auth_password",
"default":"[application_password]"
}
]
}
This method will not delete the mime file used unless specifically specified by setting the delete_mime_file settings to *YES using the mailtool_setValue() function.
It should be noted that the recipient(s) specified WILL receive the email even if they are not in the original email/MIME file. Also, the subject of the email, even if set in your program when resending using a MIME file, will remain the same as the original email and cannot be changed.
You can also resend emails using G4MS and the MAILTOOL Plus ILE functions. The requirments are simpler for this in that you are only required to specify the FROM address (that should match the account that is set up and registered in G4MS).
H DFTACTGRP(*NO) BNDDIR('BVSTOOLS')
****************************************************************
* Prototypes *
****************************************************************
/COPY QCOPYSRC,P.MAILTOOL
****************************************************************
D errMsg S 256 INZ
D rc S 10i 0
D msgid S 13S 0
****************************************************************
/free
if (mailtool_init() >= 0);
rc = mailtool_setValue('from_email':'bvstone@bvstools.onmicrosoft.com');
rc = mailtool_setValue('send_with_server_type':'*G4MSMAIL');
rc = mailtool_setValue('mime_file':'/tmp/mime6mb.txt');
rc = mailtool_sendMail(errMsg:msgid);
endif;
*INLR = *ON;
/end-free
As shown in this example all we are specifiying is the account to send the email, the send with type of *G4MSMAIL and the MIME file itself.
Again, the MIME file will not be deleted unless the value of delete_mime_file is set to YES using the mailtool_setValue() function.
Note: In the past, the Office 365 servers seemed limited to 4mb, but now they claim to be a maximum of 150mb
If you only have G4MS and the Send Email Addon (G4MSMAIL) licensed, you can also see this example.
If you use GMail for your email services and have G4G licensed, you can also send emails with a pre-created MIME file. Again, the only requirement for this method is specifying a FROM email address that matches the account you want to send the email from, and that is set up and registered in G4G.
The following is an example program:
H DFTACTGRP(*NO) BNDDIR('BVSTOOLS')
****************************************************************
* Prototypes *
****************************************************************
/COPY QCOPYSRC,P.MAILTOOL
****************************************************************
D errMsg S 256 INZ
D rc S 10i 0
D msgid S 13S 0
****************************************************************
/free
if (mailtool_init() >= 0);
rc = mailtool_setValue('from_email':'bvstone@gmail.com');
rc = mailtool_setValue('send_with_server_type':'*G4GSMAIL');
rc = mailtool_setValue('mime_file':'/tmp/mimetest.txt');
rc = mailtool_sendMail(errMsg:msgid);
endif;
*INLR = *ON;
/end-free
If you only have the G4G Send Mail application licensed you can also use this example.
As always, feel free to contact us with any questions.