SEND_MAIL
Use the SEND_MAIL script function to send an email to a user. This script function does not verify whether the specified receiver actually exists. The message is sent even if the receiver is not correct. If the email cannot be sent because the attachment cannot be found or the email connection is not active, script processing continues by default. In this case, this script function returns the corresponding return code.
Important Considerations
Key considerations include:
- To be able to send emails, make sure that the email connection is already configured, see Setting Up Email Connections.
- This script function always sends emails either through the specified agent or the Automation Engine. Therefore, the files that should be attached must be accessible through the agent or the Automation Engine either directly or through a UNC path.
- This script function writes all open transactions of the script to the AE database. For more information, see Script Processing.
- Tip: Use the :ON_ERROR script statement to define actions that should take place if the email cannot be sent successfully. For more information, see Script Elements for Error Handling.
Syntax
SEND_MAIL (Receiver, [Cc], Subject, Text [, Attachment] [, Agent] [, Login] [, MYSERVER])
Parameters
| Parameter | Description | Format | Allowed Values | Default Value |
|---|---|---|---|---|
| Receiver | The address(es) to which the message should be sent. | Script literal or script variable (Maximum 255 characters) | n.a. | n.a. |
| Cc | (Optional) The person that should receive a copy of this message. | Script literal or script variable (Maximum 255 characters) | n.a. | "" |
| Subject | Short description of the message. | Script literal or script variable (Maximum 255 characters) | n.a. | n.a. |
| Text | Message text. | Script literal or script variable | n.a. | n.a. |
| Attachment | (Optional) Path and name of the files that should be sent as an attachment. Separate the individual paths with a semicolon (;) if you want to send several files. | Script literal or script variable | n.a. | "" |
| Agent |
(Optional) Specifies the agent that should be used for sending the email message(s). If you do not specify this parameter, the default value is used. The system searches for client-wide settings that are defined in the SEND_MAIL_DEFAULT key of the UC_CLIENT_SETTINGS variable. If this key is not defined, the email is sent by through the Automation Engine. For more information, see SEND_MAIL_DEFAULT and UC_CLIENT_SETTINGS - Various Client Settings. |
Script format |
|
*DEFAULT |
| Login |
(Optional) Specifies the Login object that is used to access the email attachment(s). If you do not specify this parameter, the default value is used. The system searches for client-wide settings that are defined in the SEND_MAIL_DEFAULT key of the UC_CLIENT_SETTINGS variable. If this key is not defined, the email is sent by through the Automation Engine. For more information, see SEND_MAIL_DEFAULT and UC_CLIENT_SETTINGS - Various Client Settings. Important!
|
Name of the Login object | n.a. | n.a. |
| MYSERVER | (Optional) Allows you to define a specific SMTP server to which you want to send an email. To use this parameter, make sure that you have defined a UC_SMTP_MYSERVER static variable for each SMTP server and that each variable covers all the SMTP parameters required. The server name defined here and in the variable must match, see UC_SMTP_MYSERVER - SMTP Variable. | Script format | n.a. | n.a. |
Return Codes
Note: These are some of the possible return codes. To handle all possible return codes please use the SYS_LAST_ERR_NR script element, see SYS_LAST_ERR_NR.
-
0
Email was sent successfully
-
10034
There is no active host with email connection
-
2000142
Check JWP log for more information
-
50006
The SMTP server returned an error code
-
50007
SMTP server '&02' has rejected the E-mail recipient: '&01'
-
50012
Timeout - SMTP Server '&02' did not answer within '&01' seconds
-
50013
Error when reading attachment file '&01' error code: canRead()==false, error description: Cannot read file.
-
50014
Attachment does not exist
-
50027
Authentication on the SMTP Server failed
-
50028
The receiver address is not valid. Therefore, the SMTP Server has rejected it.
-
50029
The SMTP client cannot connect to the SMTP Server
-
50030
Error in socket creation
-
50031
Host information of the SMTP Server could not be retrieved#
-
50032
The SMTP client cannot communicate with the SMTP Server anymore
-
50033
The SMTP client cannot receive data from the SMTP Server
-
50034
Data cannot be sent to the SMTP Server
-
50035
Windows sockets cannot be initialized
-
50036
Host name of the local computer cannot be retrieved
-
50037
SMTP Server '&02' replied with Error '&01'
-
53202
The setting '&01' you are searching for was not found
Examples
The following example sends an email to exactly one user, the cc parameter is not used. One file is attached to this email.
:SET &OUT# = SEND_MAIL('brown@automic.at',, 'Meeting', 'Meeting today at 5pm', '/AE/agenda')
An email that includes two attachments is sent to several persons:
:SET &OUT# = SEND_MAIL("brown@automic.at;smith@automic.us",, "Meeting", "Meeting canceled", "c:\AUTOMIC\agenda.doc;c:\AUTOMIC\dates.txt")
The following example includes an SMTP mail server definition to which you send your email. The agent parameter is set to &AGENT# and refers to an agent called JAVAOSAGENT. Therefore, the SEND_MAIL command is sent through the JAVAOSAGENT if available. The last parameter is set to &SMTP_SERVER# and refers to LOCALHOST. Thus, the system uses the UC_SMTP_LOCALHOST static variable to get information on email settings such as SMTP_TIMEOUT, SMTPS_CERT, etc. If this variable does not include the required settings, the ones of the UC_CLIENT_SETTINGS variable are used.
:SET &RECEIVERS# = "firstuser@broadcom.com;seconduser@broadcom.com"
:SET &CC# = "thirduser@broadcom.com"
:SET &SUBJECT# = "Update on meeting"
:SET &MAILBODY# = "Hello everyone, today's meeting is canceled. Kind regards"
:SET &ATTACHMENT# = "C:\Demo\Broadcom_Ltd_Logo.svg"
:SET &AGENT# = "JAVAOSAGENT"
:SET &AGENT_MAIL_AUTH# = "LOGIN.MAIL.WINDOWS"
:SET &SMTP_SERVER# = "LOCALHOST"
:SET &MAIL_RETURN_CODE# = SEND_MAIL(&RECEIVERS#, &CC#, &SUBJECT#, &MAILBODY#, &ATTACHMENT#,,, &SMTP_SERVER#)
See also: