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!

  • To send emails, you must have configured the Email connection. For more information, see Notification (CALL).
  • 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 statement causes all open transactions of the script to be written 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

  • SEND_MAIL
    Sends an email to a user

  • Receiver
    The address(es) to which the message should be sent
    Format: script literal or script variable
    Maximum length: 255 characters

  • Cc
    (Optional) The person that should receive a copy of this message
    Format: script literal or script variable
    Default value: ""
    Maximum length: 255 characters

  • Subject
    Short description of the message
    Format: script literal or script variable
    Maximum length: 255 characters

  • Text
    Message text
    Format: script literal or script variable

  • 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.
    Format: script literal or script variable
    Default value: ""

  • 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 UC_CLIENT_SETTINGS - Various Client Settings.
    Use one of the following values:

    • Fixed string *DEFAULT (default)
    • Fixed string *SERVER. Use this string to force that the email is sent by the AE/server even if you set a central Agent/Login in the UC_CLIENT_SETTINGS variable.
    • Name of the Agent object.
      Important!
      • The specified agent and the Automation Engine system must have the same version.
      • This parameter only works with Java-based OS agents.
  • Login
    (Optional) Specifies the Login object that is used to send 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 UC_CLIENT_SETTINGS - Various Client Settings.
    Important!
    • The Login object used must have an entry with the type MAIL.
    • This parameter is mandatory combined with the Agent parameter.
    • You must have access rights to the files you want to send as attachments.
    • This parameter is ignored if the Agent parameter *SERVER is used. In this case, no Login object is required.

    Value: Name of the Login object

  • MYSERVER
    (Optional) Allows you to define a server name to which you want to send a mail. If you define this parameter, ensure that you create a separate UC_SMTP_MYSERVER static variable that includes all the required SMTP parameters and shows the name of the server you define here in its name. For more information, see UC_SMTP_MYSERVER - SMTP Variable

Return Codes

  • 0
    Email was sent successfully
  • 10034
    There is no active host with email connection
  • 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
  • 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 people:

: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 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 &SMTP_SERVER# = "LOCALHOST"
:SET &MAIL_RETURN_CODE# = SEND_MAIL (&RECEIVERS#,&CC#,&SUBJECT#,&MAILBODY#,&ATTACHMENT#,,,&SMTP_SERVER#)

See also: