In this post I’ll show you how to send a mail from adonix code in Sage X3.
The points we will face are:
1) Meladx/Send introduction
2) Sending through meladx (the best way for me: at the end with just a single code line you send a mail!)
3) Sending through Workflow
4) Sending through ENVOI_MAIL(…) From AWRKMEL
2) Sending through meladx (the best way for me: at the end with just a single code line you send a mail!)
3) Sending through Workflow
4) Sending through ENVOI_MAIL(…) From AWRKMEL
Sending mail from code in Sage X3: Send vs meladx
Sage X3 has two native ways for sending mails.
The first way is meladx executable file, that you can find in runtime\bin directory.
The seconde one is Send instruction, that was used to send mail through an application of the client station (for more information on “Send GSERMES” go here).
The first way is meladx executable file, that you can find in runtime\bin directory.
The seconde one is Send instruction, that was used to send mail through an application of the client station (for more information on “Send GSERMES” go here).
The Meladx executable
Meladx send messages through SMTP/POP3 protocols by means of the mail server specified in the command.
When sending is launched by a workflow or other Sage X3 predisposed systems (for instance via batch),
the server envolved is defined in SERMES variable of supervisor chapter (ADPVAL function).
When sending is launched by a workflow or other Sage X3 predisposed systems (for instance via batch),
the server envolved is defined in SERMES variable of supervisor chapter (ADPVAL function).
The Send instruction
The Send instruction send the mail messages with MAPI protocol through the client station that is executing Sage X3.
It’s not usable by web. It serve for sending from client application.
Client station must have a mail client MAPI, and this client must be in execution.
It has 500 byte limit foe message (excluding attachments; meladz limite is 64kb).
It’s not usable by web. It serve for sending from client application.
Client station must have a mail client MAPI, and this client must be in execution.
It has 500 byte limit foe message (excluding attachments; meladz limite is 64kb).
Also a Seldest function exist, and it was allowing to make final user insert the recipients and other informations.
In this post we will not be talking about this client call.
In this post we will not be talking about this client call.
Sending a mail through meladx command
The executable meladx is a native command of Sage X3 system; it uses SMTP/POP3 protocols
and in practice it uses a structured file with needed data for sending the mail.
and in practice it uses a structured file with needed data for sending the mail.
Here an example that you can launch from both command prompt and a SYSTEME call.
meladx -v -s mail.server.com -r from@test.com < C:\file.txt
The file content could be:
Once the operation has been understood write a function for writing runtime the file is easy:
Just recall it like this::
In fact, once this function is inserted in an our library, with a simple call we do all!
meladx and attachments
For sending attachments with meladx, just add similar lines to following to the end of the file:
Sending through Workflow
These are the steps for implementing a simple example:
- create a YMA event in 908 table of Miscellaneous tables (funzione GESADI); we can put “Sending mail by program” as description;
create always a new event code to avoid interfering with preexisting other uses;
(note that activity code can not be put in a single item, so this is one of that activities the you have to annotate for checking it in case of Sage X3 updating). - create a YMAIL workflow (GESAWA function)
- set event code as YMA
- Event type: “Miscellaneous”,
- in the “Management” box of “General” tab check “Trigger Mail field”
- in the “Recipient” tab insert a line with “User” as Type and
GYRECIPIENT
as Recipient (GYRECIPIENT is a global variable that will be defined by program), Send mail “Yes” and the other fields “No” - in the “Message” tab
- in the object field write
GYOBJECT
- in the text field write
|GYMAILTEXT|
(between two vertical bars, to tell the system that this is a variable in the middle of a fixed text)
- in the object field write
- create the rule
For sending a message mail you just call the following code
Kill instructions are necessary for deleting the temporary global variables.
Workflow and attachments
Sending mail through workflow allows you to attach files in different ways.
“Attached document” field
The first option is inserting in “Attached document” field in the “Message” tab of workflow the absolute path of file to attach.
You can also insert a global variable name valorized opportunely by program.
For inserting more files just separate the paths with a “;” (semicolon); here same examples:
"filename1.txt;filename2.txt"
GFILPATH+";"+GYFILE2
Attaching a file attached to the object
As you can see in the standars windows of Sage x3 (for instance invoices or orders windows),
in the right menu there is an icon that allow the user to attach any files to current object.
The path of these file is assciated with a type and a category.
in the right menu there is an icon that allow the user to attach any files to current object.
The path of these file is assciated with a type and a category.
These files attached to the object can also be attached to eventual mail using a workflow with “Object” as Event type.
In the “Message” tab (in workflow configuration) you can choose:
In the “Message” tab (in workflow configuration) you can choose:
- if attach to mail the attached files to the object (“Attachment” flag)
- if attach all type of files attached to the object (“All types” flag) or what types to attach
- if attach all categories of attachments or what categories (“All categories” flag)
These attachments are added to that indicated in the “Attached document” field.
Sending mail through ENVOI_MAIL(…) From AWRKMEL
A third way is directly calling the function used by workflows to sending mail.
There is an example in the blog of the expert Matteo Carminati,
There is an example in the blog of the expert Matteo Carminati,