Sendmail

3.3.5 Sendmail

DESCRIPTION

Sendmail - Send an E-mail. The command acts as an SMTP client and sends E-mails with eventual attachments through an SMTP server. To receive email use the Mail command.

Supported authentication schemes are no security (public/anonymous mail servers), plain user/password authentication or OAuth2 authentication to Google or Microsoft IMAP servers (since 6.2.3). The communication may be either unencrypted or encrypted with STARTTLS (since 4.1.3). Version 4.4.3 introduced support of SSL secured SMTP (typically port 465). The connection type is picked up automatically based on the port and doesn't have to be specified by the command. If the server is using a custom port you may have to set the security type manually in the command preferences.

Optional attachments are sent in the Base64 encoding.

If default values of from, to, server, user and passwd are provided in the Sendmail preferences they may be omitted in the command.

SYNOPSIS

sendmail [from=<sender_address>]  [to=<recipient_address>]  [server=<server[:port]>]  [cc=<recipient_address>]  [bcc=<recipient_address>]  [subject=<subject>]  [text=<mail_body>]   [attach=<attachments>]  [user=<userId>]   [security=<none|password|google|microsoft>]  [passwd=<password>]  [delayed=<true|false>]  [debug=<true|false>]
* Parameters are obligatory unless valid default values are provided through Sendmail preferences 

OPTIONS

from=<sender_address>

The sender E-mail address or a comma separated list of addresses, for example john.doe@company.com.

to=<recipient_address(es)>

The recipient E-mail address, for example jane.doe@company.com.

cc=<recipient_address(es)>

The Carbon Copy (CC) E-mail address or a comma separated list of addresses (since 5.0.3).

bcc=<recipient_address(es)>

The Blind Carbon Copy (BCC) E-mail address or a comma separated list of addresses (since 5.0.3).

server=<server[:port]>

The SMTP server to send the mail message through. If just a hostname without a port number is used, the command attempts to connect the server on the standard SMTP port of 25.

security=<none|password|google|microsoft>

The security type (since 6.2.3), one of:

    • "none" - anonymous access.
    • "password" - plain password authentication. The password may be specified through the password parameter.
    • "google" - OAuth2 authentication to the GMail SMTP server.
    • "microsoft" - OAuth2 authentication to the MS Outlook SMTP server.

To enable either of the OAuth2 schemes you have to download the authentication token through the Tools→OAuth Token Manager window. Tokens are long lived but may be invalidated on the user side (password change, revocation through the Google Dev Console or MS Azure account, ...) or after they are not used for a long time (typically 6 months). Downloaded tokens are encrypted and stored in the Robot configuration file.

If the security parameter is omitted the command defaults to either "none" or "password" security depending on whether the password is specified.


passwd=<password>


The password to authenticate to the SMTP server. It is used only when the security is set to "password".

subject=<subject>

The mail subject (title).

text=<mail_body>

The mail body. If the text starts with "<html>" the content type is set to HTML. Otherwise, the content is sent as plain text. To indicate a line break use '\n'. If you need to use '\n' in the normal text, double the backslash character ('\\n').

attach=<attachments>

List of attachments i.e. files to attach to the E-mail. File names must be separated by a semicolon (';'). On Linux/Unix make sure the file name doesn't contain semicolon because the list would be incorrectly parsed. If an attachment is not found, it is ignored and the mail is sent without it. It is recommended to provide the files with an absolute path.

user=<username>

The user ID to authenticate to the SMTP server with. This option should be used together with the passwd parameter when the SMTP server specified by the server parameter requires plain password authentication.


delayed=<true|false>

When set true the email will be delayed until after the script finishes (supported since 4.1.3). This is useful for example when the script needs to send the test results (report) by email and doing so without a delay would show the status of "Running" in the data. The default value is false (send immediately).

debug=<true|false>

Debug flag. Use debug=true to switch on the JavaMail debugging console output. This is useful if you need to find out why the E-mail feature doesn't work.

RETURNS

The command returns 0 (zero) on success or 1 if the E-mail cannot be sent.

EXAMPLES

Screenshot scr.png
Sendmail to="tester@dummyserver.com" from="robot@dummyserver.com" server="mail.dummyserver.com" subject="Screenshot of the remote desktop" text="Please check the attached screenshot."attach="{_REPORT_DIR}/scr.png"

- Take a screenshot of the current remote desktop and send it by E-mail to user tester@dummyserver.com.

Sendmail subject="Hello" text="This is a multiline E-mail.\nSecond line.\nThird line." 

- Example of a multiline E-mail. This command will only work if you have set correct default values of the 'from','to' and 'server' parameters in the Sendmail command preferences.

Sendmail subject="HTML Example" text="<html><body><h1>Hi there!</h1>How are you?</body></html>" 

- Example of an HTML E-mail. This command will only work if you have set correct default values of the 'from','to' and 'server' parameters in the Sendmail command preferences. 

Sendmail delayed="true" subject="Script finished" text="<html><body>Script <i>{_FILENAME}</i> finished with the exit code of {_EXIT_CODE}. See the results <a href=\"http://myserver.mydomain.com/reports/{_REPORT_FILE_RELATIVE}\">here</a>.</body></html>"

- Example of an email notifying the recipient that the script has finished. As the 'delayed' parameter is set to true the mail will be sent after the script gets finished. We presume that the report directory is linked to the reports/ folder under the document root of a web server on host myserver.mydomain.com. For simplicity we also presume that you have set correct default values of the 'from', 'to' and 'server' parameters in the Sendmail command preferences.