E-mail Functions
AMT provides a set of functions for handling e-mail. With these functions e-mails can be created, sent, read and managed from with forms and reports.
The following functions are available:
Function |
Description |
|||||
ADDATTACHMENT |
Sets the attachment(s) of the e-mail to be sent. |
|||||
Use: |
||||||
<E-mail id>.ADDATTACHMENT (<Filename(s)>) |
||||||
<Filename(s)> |
Specification (string) to point to the file(s) that must be sent with the e-mail. A path may be included. Multiple filenames should be separated by a semicolon (;). |
|||||
BCC |
Sets the BCC (blind carbon copy) of the message to be sent. Multiple addresses should be separated by comma's. |
|||||
Use: |
||||||
<E-mail id>.BCC := <Destination> |
||||||
<Destination> |
Specification (string) of the address(es) to be included in the BCC of the e-mail. The BCC address(es) will be omitted in the e-mail that is received by the recipient. |
|||||
CC |
When sending the e-mail(s): |
|||||
Use: |
||||||
<E-mail id>.CC := <Destination> |
||||||
<Destination> |
Specification (string) of the address(es) to be included in the CC of the e-mail. |
|||||
When receiving the e-mail(s): |
||||||
Use: |
||||||
<Variable> := <E-mail id>.CC |
||||||
<Variable> |
Name of the variable that must store the CC addresses. |
|||||
CLEARMESSAGE |
Clears all settings for the e-mail to be sent. |
|||||
Use: |
||||||
<E-mail id>.CLEARMESSAGE () |
||||||
CONTENT |
When sending the e-mail(s): |
|||||
Use: |
||||||
<E-mail id>.CONTENT := <Content> |
||||||
<Content> |
Message content for the e-mail. |
|||||
When receiving the e-mail(s): |
||||||
Use: |
||||||
<Variable> := <E-mail id>.CONTENT |
||||||
<Variable> |
Name of the variable that must store the message content. |
|||||
DELETEMESSAGE |
Marks the current received e-mail message for deletion. E.g., if you fetch 4 messages from your mailbox and you only use the function DELETEMESSAGE after you fetched the 4th message, than only the 4th message will be deleted. The other 3 messages will be kept on the POP3 server. The DELETEMESSAGE is always the last function that is called within an E-mail receiving routine. Please note that the physical deletion will only be done at POP3LOGOFF (which is part of the POP3 protocol). |
|||||
Use: |
||||||
<E-mail id>.DELETEMESSAGE () |
||||||
FROM |
When sending the e-mail(s): |
|||||
Use: |
||||||
<E-mail id>.FROM := <Address> |
||||||
<Address> |
Specification (string) of the sender address that must be included in the e-mail. |
|||||
When receiving the e-mail(s): |
||||||
Use: |
||||||
<Variable> := <E-mail id>.FROM |
||||||
<Variable> |
Name of the string variable that must store the FROM address. |
|||||
GETATTACHMENTS |
Returns a list with the filenames of the attachments and puts the physical files in the specified directory. |
|||||
Use: |
||||||
<E-mail id>.GETATTACHMENTS (<Directory>) |
||||||
<Directory> |
Directory to which the attachments must be copied. |
|||||
GETNROFMESSAGES |
Returns the number of messages (integer) at the mailserver.
|
|||||
Use: |
||||||
<Variable> := <E-mail id>.GETNROFMESSAGES |
||||||
<Variable> | Name of the variable that must store the number of messages at the mailserver. | |||||
GETRECEIVEDDATE |
Returns the date (string) that the message was received. |
|||||
Use: |
||||||
<Variable> := <E-mail id>.GETRECEIVEDDATE |
||||||
<Variable> | Name of the string variable that must store the receive date. | |||||
POP3LOGON |
Logs on to the POP3 server that must be used for fetching the e-mail. |
|||||
Use: |
||||||
<E-mail id>.POP3LOGON (<Servername>, <Serverport>, <Username>, <Password>[, <UseSSL>]) |
||||||
<Servername> |
Name of the POP3 server (string) to connect to. |
|||||
<Serverport> |
Portnumber (integer) that must be used for the connection. |
|||||
<Username> |
Username (string) for the login. |
|||||
<Password> |
Password (string) that applies to the username that is specified for the login. |
|||||
<UseSSL> |
Boolean switch, when True SSL/TLS will be used for the POP3 connection. Defaults to False. |
|||||
POP3LOGOFF |
Logs off and disconnects from the POP3 server. |
|||||
Use: |
||||||
<E-mail id>.POP3LOGOFF () |
||||||
READMESSAGE |
Checks the POP3 server on new e-mail messages for the e-mail account and fetches all data (in "TO", "CC", "SUBJECT", etc.) of the current e-mail or (if specified) the e-mail to which is pointed through the <Message no> specification. If this function is performed more than once, then each time it will fetch the next message. If there are no messages, then the internal message counter will be reset, and a new message that is received can be fetched subsequently. |
|||||
Use: |
||||||
<E-mail id>.READMESSAGE ([<Message no>]) |
||||||
<Message no> |
Number that points to the e-mail message that must be fetched. |
|||||
SENDLASTRECEIVEDMESSAGE |
Sends the last received message to a new destination. In fact, this function is just a forward of the current message. This function is always preceded by the functions READMESSAGE and TO (and in most cases FROM). |
|||||
Use: |
||||||
SENDLASTRECEIVEDMESSAGE |
||||||
SENDMESSAGE |
Sends the previous built e-mail to the SMTP server. Before executing this instruction, all mandatory preparations for building the e-mail should have been made. When the used e-mail address is in a incorrect format an error will returned and ResOk will be set to false. |
|||||
Use: |
||||||
<E-mail id>.SENDMESSAGE () |
||||||
SETFORMAT |
When sending the e-mail(s): Sets the format for the message to be sent. When receiving the e-mail(s): Sets the format for the received message(s). |
|||||
Use: |
||||||
<E-mail id>.SETFORMAT (<Format>) |
||||||
<Format> |
Specification of the format of the message, which can be one of the following: |
|||||
SMTPLOGOFF |
Logs off and disconnects from the SMTP server. |
|||||
Use: |
||||||
<E-mail id>.SMTPLOGOFF () |
||||||
SMTPLOGON |
Logs on and connects to the SMTP server. |
|||||
Use: |
||||||
<E-mail id>.SMTPLOGON (<Servername>, <Serverport>[, <Username>, <Password>, <UseSSL>]) |
||||||
<Servername> |
Name of the SMTP server (string) to connect to. |
|||||
<Serverport> |
Portnumber (integer) that must be used for the connection. |
|||||
<Username> |
The username to use for the logon |
|||||
<Password> |
The password to use for the logon |
|||||
<UseSSL> | Set to True to enable the use of SSL/TLS, the default value is False. | |||||
SUBJECT |
When sending the e-mail(s): |
|||||
Use: |
||||||
<E-mail id>.SUBJECT := <Subject> |
||||||
<Subject> |
Specification of the subject (string) to be included in the e-mail. |
|||||
When receiving the e-mail(s): |
||||||
Use: |
||||||
<Variable> := <E-mail id>.SUBJECT |
||||||
<Variable> |
Name of the string variable that must store the subject description. |
|||||
TO |
When sending the e-mail(s): |
|||||
Use: |
||||||
<E-mail id>.TO := <Recipient> |
||||||
<Recipient> |
Specification of the TO (string). It is allowed to specify multiple recipients. The e-mail addresses of multiple recipients should be separated by comma's. |
|||||
When receiving the e-mail(s): |
||||||
Use: |
||||||
<Variable> := <E-mail id>.TO := <Recipient> |
||||||
<Variable> |
Name of the string variable that must store the TO addresses of the e-mail.. |
Example
The first example starts with GetNrOfMessages(), which then uses a for loop to iterate from 1 to the number of messages, calling ReadMessage with the iterator for an argument:
const
var
em : email
i : integer
messageCount : integer
booleans
end_definitions
routine main
begin_routine
messageCount := em.GetNrOfMessages()
loop for i := 1 to messageCount
em.ReadMessage(i)
em.SetFormat('TEXT')
sme ('From....:' + em.From)
sme ('To......:' + em.To)
sme ('CC......:' + em.CC)
sme ('Subject.:' + em.Subject)
sme ('Content.:' + em.Content)
sme ('Attchm..:' + em.GetAttachments('C:\TEMP\EMAIL'))
sme ('Received:' + em.GetReceivedDate)
endloop
if em.sendlastreceivedmessage ()
em.smtplogon ('SERVER', 25)
em.from := 'abc@cde.com'
em.to := 'Jansen@xyz.com'
em.sendlastreceivedmessage ()
em.smtplogoff ()
endif
em.smtplogon ('SERVER', 25)
em.clearmessage ()
em.setformat ('TEXT')
em.from := 'abc@def.com'
em.to := 'Jansen@xyz.com'
em.cc := 'Jansen@klm.com, Klaassen@abc.com'
em.subject := 'Test mail'
em.content := 'This is a @0D@@0A@ test message'
em.addattachment ('C:\boot.ini')
em.sendmessage ()
em.smtplogoff ()
end_routine
Example
You can also call a ReadMessage without an argument until it returns false:
const
var
em : email
booleans
end_definitions
routine main
begin_routine
loop while (em.ReadMessage())
em.SetFormat('TEXT')
sme ('From....:' + em.From)
sme ('To......:' + em.To)
sme ('CC......:' + em.CC)
sme ('Subject.:' + em.Subject)
sme ('Content.:' + em.Content)
sme ('Attchm..:' + em.GetAttachments('C:\TEMP\EMAIL'))
sme ('Received:' + em.GetReceivedDate)
endloop
if em.sendlastreceivedmessage ()
em.smtplogon ('SERVER', 25)
em.from := 'abc@cde.com'
em.to := 'Jansen@xyz.com'
em.sendlastreceivedmessage ()
em.smtplogoff ()
endif
em.smtplogon ('SERVER', 25)
em.clearmessage ()
em.setformat ('TEXT')
em.from := 'abc@def.com'
em.to := 'Jansen@xyz.com'
em.cc := 'Jansen@klm.com, Klaassen@abc.com'
em.subject := 'Test mail'
em.content := 'This is a @0D@@0A@ test message'
em.addattachment ('C:\boot.ini')
em.sendmessage ()
em.smtplogoff ()
end_routine