A simple email engine for ffenics 1.x

Moderators: Phil Winkler, Graham Smith, Pete Tabord

A simple email engine for ffenics 1.x

Postby Gil Fleming » Fri Sep 16, 2016 3:47 pm

We have just discovered a very user-friendly email client that can be run from the command line. It can be called with a whole load of command line switches, or the switches can be put into an xml file and then called with a standard command line. The software is called Swith Mail and it's at https://www.tbare.com/software/swithmail/.

I'm pasting in the basic code that could be used to firstly generate the xml file and then call the mail program. In this instance, I've just dropped the SwithMail exe file into my program directory (W:\) . In the attached code, I'm assembling the xml file using global variables (SetGlobal/GetGlobal). For testing, I hard code the globals at the start of the code. In a working situation, you could save this procedure and call it SwithMailEngine (you would disable the hard coding of variables at the start of the attached code). Then, in order to send an email from any part of your application, you simply run a procedure that populates all of the required globals then have the line

Code: Select all
run document SwithMailEngine .


Here is the code for xml generation and email program calling:

Code: Select all
define "r" number .
define "quote" text 1 .
define "progname" text 255 .
quote := convert("n34") .

-- FOLLOWING LINES FOR DEVELOPMENT SETTING OF GLOBALS. DISABLE IN WORKING MODEL
r:= setglobal(1, "Jim Davis" ) .
r:= setglobal(2, "jim.davis@domain.com" ) .
r:= setglobal(3, "jim.davis@domain.com" ) .
r:= setglobal(4, "VAgh6jHHg7kjywnQ== " ) .
r:= setglobal(5, "customer@theirdomain.com") .
r:= setglobal(6, "esupport@domain.com" ) .
r:= setglobal(7, "W:\InvPrnQ\Invoice_011574.pdf" ) .
r:= setglobal(8, "W:\InvPrnQ\Invoice_011575.pdf" ) .
r:= setglobal(9, "Your FT Invoice 12345 is attached" ) .
r:= setglobal(10, "W:\Customer_Statement " ) .

r:= filedelete("w:\ffSwith.xml") . -- important, or the textoutln function will append all of your code to the existing xml file

message "generating xml file..." .

r := textoutln("w:\ffSwith.xml",  concat("<?xml version=", quote, "1.0" , quote, " encoding=", quote, "utf-8", quote,  " standalone=", quote, "yes", quote, "?>") ) .
r := textoutln("w:\ffSwith.xml", "<SwithMailSettings>" ) .
r := textoutln("w:\ffSwith.xml", "<ServerSettings>" ) .
r := textoutln("w:\ffSwith.xml", concat("<FromName>", GetGlobal(1) , "</FromName>") ) . -- eg Jim Davis
r := textoutln("w:\ffSwith.xml", concat("<FromAddress>", GetGlobal(2), "</FromAddress>") ) . -- eg jim.davis@domain.com
r := textoutln("w:\ffSwith.xml", concat("<Username>", GetGlobal(3), "</Username>") ) .  -- eg jim.davis@domain.com
r := textoutln("w:\ffSwith.xml", concat("<Password>" , GetGlobal(4) , "</Password>") ) .   -- eg VAgh6jHHg7kjywnQ== this hash is generated by the GUI of SwithMail. Allows you to obfuscate the actual mail password in the XML file. You can use a human readable password, but this is less secure.
r := textoutln("w:\ffSwith.xml", "<ObscurePassword>True</ObscurePassword>") .
r := textoutln("w:\ffSwith.xml", "<MailServer>smtp.office365.com</MailServer>") .
r := textoutln("w:\ffSwith.xml", "<MailServerPort>587</MailServerPort>") . -- standard Office 365 settings
r := textoutln("w:\ffSwith.xml", "<SSL>True</SSL>") . -- needed for Office 365 mailboxes
r := textoutln("w:\ffSwith.xml", "<Encoding />") .
r := textoutln("w:\ffSwith.xml", "<RequestReceipt>False</RequestReceipt>") . -- can be hard coded as here, or set via a variable
r := textoutln("w:\ffSwith.xml", "</ServerSettings>") .
r := textoutln("w:\ffSwith.xml", "<EmailAddresses>") .
r := textoutln("w:\ffSwith.xml", concat("<To>", GetGlobal(5), "</To>") ) .  -- eg gil@fleming-tech.com
r := textoutln("w:\ffSwith.xml", "<CC />") .
r := textoutln("w:\ffSwith.xml", "<BCC />") .
r := textoutln("w:\ffSwith.xml", concat("<ReplyTo>", GetGlobal(6), "</ReplyTo>") ) .  -- eg esupport@domain.com
r := textoutln("w:\ffSwith.xml", "</EmailAddresses>") .
r := textoutln("w:\ffSwith.xml", "<Attachments>") .
r := textoutln("w:\ffSwith.xml", concat("<AttachmentPath>", GetGlobal(7) , "</AttachmentPath>") ) .   --eg W:\InvPrnQ\Invoice_011574.pdf as attach 1
r := textoutln("w:\ffSwith.xml", concat("<AttachmentPath>", GetGlobal(8) , "</AttachmentPath>") ) .   --eg W:\InvPrnQ\Invoice_011575.pdf as attach 2
r := textoutln("w:\ffSwith.xml", "</Attachments>") .
r := textoutln("w:\ffSwith.xml", "<EmailContent>") .
r := textoutln("w:\ffSwith.xml", "<HTML>False</HTML>") .
r := textoutln("w:\ffSwith.xml", "<DontReplaceNewLine>False</DontReplaceNewLine>") .
r := textoutln("w:\ffSwith.xml", concat("<Subject>", GetGlobal(9), "</Subject>") ) .    -- eg Your FT Invoice 12345
r := textoutln("w:\ffSwith.xml", "<Body />") .
r := textoutln("w:\ffSwith.xml", concat("<BodyTxtFile>", GetGlobal(10), "</BodyTxtFile>") ) .  -- eg W:\Customer_Statement  a text file with or without .txt extension
r := textoutln("w:\ffSwith.xml", "<Priority>high</Priority>") .
r := textoutln("w:\ffSwith.xml", "</EmailContent>") .
r := textoutln("w:\ffSwith.xml", "</SwithMailSettings>" ) .

message "Sending Email..." .

Progname := concat("w:\SwithMail.exe /s /x ", quote, "W:\ffSwith.xml", quote) .
-- message progname window .  -- activate this line to debug your command line if it isn't working the way you expect
call program progname .



SwithMail supports SSL/TLS security (a requirement if your email is hosted via Office365) and some simple html tags in the body text. Incidentally, you can add body text from a variable or simply include the path to a pre-written text file. You can specify multiple attachments as wll as cc and bcc recipients. There's no installation, as such - just drop the SwithMail exe file wherever it suits you.
Gil Fleming
Director
Fleming Technical Limited

You can't think about what you don't know - Mike Fidler
If you can't fight, wear a big hat - John S Fleming
The best way to have a good idea is to have lots of ideas - Linus Pauling
Gil Fleming
 
Posts: 546
Joined: Tue May 15, 2012 10:26 am
Location: Liverpool, UK
Has thanked: 1 time
Been thanked: 2 times
 
 

Return to Ffenics 1.x

Who is online

Users browsing this forum: No registered users and 9 guests

cron