Connect to SMTP Server

Connects to an SMTP email server, storing the established connection in a variable.

Command availability: IBM RPA SaaS and IBM RPA on premises

Description

Connects to an SMTP email server, storing the established connection in a variable.

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

smtpConnect --smtphost(String) [--smtpport(Numeric)] [--smtpusername(String)] [--smtppassword(String)] [--smtpusessl(Boolean)] [--enableLog(Boolean)] (EmailConnection)=value

Limitations

  • If you use Gmail or Outlook, use Integration Connection instead of Basic Authentication. These services require additional authentication to connect with their services, and you need a valid Connection to connect to these services.
  • To send emails the connection must use the original email account and not an alias. Connections using an aliased email account can only read emails. The workaround is to add your email provider to the Microsoft™ Outlook service and use the Connect to Microsoft Outlook (microsoftMailConnect) command.

Dependencies

  • If you are using the IntegrationConnection authentication type, refer to Connections.
Important:SMTP connections only support sending emails.

Input parameters

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
SMTP Host smtphost Required Text SMTP address of the mail server.
SMTP Port smtpport Optional Number SMTP server TCP port used for the connection.
Authentication Type authenticationtype Required Text The type of authentication. See the authenticationType parameter options.
SMTP Connection smtpconnection Required when the authenticationtype parameter is IntegrationConnection text Use a Connection to connect with the SMTP service.
SMTP User name smtpusername Optional Text Client username registered on the SMTP server.
SMTP Password smtppassword Optional Text Client user password registered on the SMTP server.
Use SSL for SMTP smtpusessl Optional Boolean Enables the use of the SSL External link security protocol for SMTP.
Enable log enableLog Optional Boolean Enables protocol logging, if available.

The log file is stored in the %localappdata%\IBM Robotic Process Automation directory.

authenticationType parameter options

The following table displays the options available for the authenticatinType input parameter. The table shows the options available when working in Script mode and the equivalent label in the Designer mode.

Designer mode label Script mode name Description
Basic Authentication basicAuthentication Uses basic authentication to authenticate third-party accounts. Requires User name and password.
Integration Connection integrationConnection Uses Oauth authenticated connections from the tenant you're logged in.

If you have problems connecting to a service using Basic Authentication, use the Integration Connection instead. Some services, such as Gmail and Outlook, can block access to certain applications and require additional authentication.

To use an Integration Connection, you must configure your connection in the IBM RPA Control Center. For more information, see:

Output parameters

Designer mode label Script mode name Accepted variable types Description
Connection value Email Connection Collection containing all messages from the account's email boxes.

Example

Example 1: If you use services such as Gmail or Outlook, you must use Connections to connect with an SMTP email server. These services block unauthorized applications from accessing your email account, and require an OAuth authentication method to provide access to their services. You must configure a valid Connection before you use these email services. For more information, see Adding connections to an application.

The following example demonstrates how to effectively send an email using a Connection in Gmail:

defVar --name emailConnection --type EmailConnection
defVar --name receiverList --type List --innertype String --value "[\"receiver@example.com\"]"
smtpConnect --smtphost "smtp.gmail.com" --smtpport 587 --authenticationtype "IntegrationConnection" --smtpconnection rpa_test_gmail --smtpusessl  emailConnection=value
emailSend --connection ${emailConnection} --to ${receiverList} --from "example@gmail.com" --subject "Hello, World!" --bodytype "Text" --body "Hello, World! You are receiving this email from an automated service."

Example 2: Using Basic Authentication, the following example sends an email without additional authorization:

defVar --name emailConnection --type EmailConnection
defVar --name receiveremail--type List --innertype String --value "[email@example.com]"
smtpConnect --smtphost "smtp.example.com" --smtpport 465 --smtpusername "useremail@gmail.com" --smtppassword userpassword --smtpusesslemailConnection=value
emailSend --connection ${emailConnection} --to ${receiverEmail} --from "useremail@gmail.com" --bodytype "Text" --body "Message body"
emailDisconnect --connection ${emailConnection}