In axion, you can send emails, which are known as 'channels'. The 'def_channel' table has all of the fields required for the system to generate an email.
The following are the most noteworthy columns in def_channel:
-- The name of the channel to the axion system.
-- The address that will send the email.
-- The HTML of the email. This field is string processed, so system variables such as $user$ can be used.
-- The file format of a report attached to the email.
--The name of the report that you would like to attach as a file. This report must have the Reporttype of 'EMAIL' in def_report.
There are three ways to send an email, either directly through the axion system, or through a workflow.
Sometimes it is easier to test a channel directly rather than having to design a full workflow for it. The python used to send a channel is stored in the python folder /factory.core/ObjChannelmail.py. This can be run using the python command (as long as you are in the development environment). To directly send a channel, the following structure is needed (assuming that you are in the base axion directory:
python factory.core/ObjChannelmail.py channel_name email_address
for example:
python factory.core/ObjChannelmail.py welcome_email bob@technocore.ac.za
A Channel can be sent through a workflow. This requires a number of steps. Firstly, axion will always look for a variable named 'email', and send the channel to that address. There are two ways in which you can set email. Firstly, if you are activating the workflow from a form that has a field called 'email', the system will use that email. Secondly, you can do a calculation before sending the email. In the calculation, select the email that you want to send as 'email', this will tell the system that you want to send your channel to that person. Make sure that you have 'HasResult' set to 'Y' when doing this, otherwise the system will not store email as a variable.
SELECT "bob@technocore.az.za" as email
After the calculation, you can create a workflow node of "Type" = "EMAIL", with the "Name" being the name of the channel. Now whenever the workflow is activated, an email will be sent to Bob.
One of the useful things about the calculation steps is that you can also select other variables. For example:
SELECT "bob@technocore.az.za" as email, 19 as age
Now in your channel, you can put $age$ anywhere and it will be swapped out with the number 19.
Within the workflow node there is a column called Async, asynchronous emails will be explained later, but in almost all cases it is better to set this column to "Y".
The SQL table stage_channel is a way to set emails to be sent. The following columns are useful:
A dispatcher will detect if staged channel has not been queued, and will queue it, setting the Status to "mq", then a consumer will find the channel in the queue and send it. After which the Status will be set to "DONE".
In previous versions of Axion, when an channel was sent the pipeline would have to wait for the email to be processed before it could continue. Now, channels are asynchronous by default. This means that workflows will send the details of a channel to a MongoDB with a Status of "Pending". The workflow will then continue.
A dispatcher worker running on another instance will then pick up that there is a channel pending and add its details into a RabbitMQ queue. Finally a consumer worker will send the email.
Each of these stages are documented within the MongoDB database with a collection name of {package}_axion_channel.
If supervisorctl is running, there will already be dispatchers and consumers to process async channels. However, if you want to see what is happening during your asynchronous calls, it may be useful to run the workers individually in terminals. The following commands are used to control supervisorctl (in terminal):
supervisorctl start allsupervisorctl stop allNow that supervisorctl is not active, all channels that are staged will remain "Pending", and all channels that were queued ("mq") will remain queued. Two workers are now needed, one to queue and one (or more) to send the emails. These must run in two terminals. In separate terminals run the following two codes from the axion folder:
python factory.core/ObjChannelmail.py dispatcher
python factory.core/ObjChannelmail.py worker
Now you will be able to see what is happening to your asynchronous channels.
To add email variables without using a workflow calculation, the ContextSQL column can be used. This takes a SQL query, and the outputs of the SQL query can be used within the Notes of the email.
SELECT * FROM data WHERE AccountCode = '$param2$'
The above code creates a variable for every column in data (Assuming AccountCodes are unique). In the HTML of Notes, these variables can be called using the default method.
<p>We are thrilled to welcome you to our $db_postaladdr4$ platform!</p>
To add an image to your email, you must use the following format:
https://{sitename}/glyph/channel/$guid$/{imageName}
The image should be stored in resource.templates/package.{package}
This image can be tracked within the MongoDB database. When an image URL is called, a tracker will add the following to the document of a channel:
Status:"DONE"
activated:true
activatedAt:2025-01-13T10:43:24.415+00:0
In this way, we can know if someone has opened an email sent to them.
To add an excel document, the Attachmentreporttype must be XLS and the Attachmentreport must be the Reportcode of the report that you would like to turn into a spreadsheet.
The ReportType of the Excel report should be "EMAIL".
If done correctly, every time that the channel is sent, it will have an Excel attachment of the data stored in the report.