Skip to content

SMTP Send

Type: smtp-send  ·  Package: SMTP / IMAP Email Activities v1.0.5

Sends an email through an SMTP server, without Outlook installed. It supports several recipients, carbon copy (CC) and blind carbon copy (BCC), reply-to address, text or HTML body, and attachments. It is the activity for sending notifications, reports and confirmations from a robot, also in unattended execution.

  1. Builds the message: sender (from, or username if not set), recipients, subject, body (text or HTML depending on isHtml) and attachments. If an attachment is missing, it fails before connecting, so no incomplete email goes out.
  2. Connects to host:port with the security encryption (default auto on port 587: STARTTLS if the server offers it), signs in with username and password, sends and disconnects.

Recipients (to, cc, bcc) can be a text with addresses separated by commas ("ana@company.com, luis@company.com") or a list. Each address can carry a display name: "Ana Smith <ana@company.com>". The connection data is that of the sending server.

Each run sends a new email: if you put it inside a Retry, a retry after a send that did go through produces a duplicate.

ParameterTypeDefaultDescription
hoststring—SMTP server (e.g. smtp.gmail.com).
usernamestring—Username used to sign in (usually the full address).
passwordcredential—Password or App Password. Use credential("name")["password"].
tostring | List—Recipient(s): text with comma-separated addresses, or a list of addresses. At least one is required.
subjectstring—Subject.
bodystring—Email body (plain text, or HTML with isHtml = true).
ParameterTypeDefaultDescription
portint587SMTP port. With security = ssl it is usually 465.
fromstringusernameSender address; accepts "Name <address>". Many servers require it to be the signed-in account or an authorized alias.
replyTostring—Address that receives replies (Reply-To).
isHtmlboolfalseThe body is HTML.
ccstring | List—CC: comma-separated text or list.
bccstring | List—BCC: comma-separated text or list.
attachmentsstring | List—A text with one file path, or a list of paths. All files must exist.
securitystring"auto"Encryption: auto, none, ssl or starttls. See Encryption and ports.

This activity does not return a value. The log says how many recipients (to + cc + bcc) the email was sent to.

MessageCause and fix
'host' is required. (and the same for username, subject, body)The parameter is missing or the expression returned null. For an empty body use "".
At least one recipient is required in 'to'.to is empty or the list contains no texts.
Attachment file not found.A path in attachments does not exist. Check it first with File Exists; the email is not sent.
Error parsing an addressAn address in from, to, cc, bcc or replyTo is invalid (for example, separated with ; instead of a comma).
Server authentication errorWrong username or password, or the account requires an App Password.
Connection or TLS errorWrong host or port, or security does not match the port (for example ssl on 587). Use 587 + auto/starttls or 465 + ssl.

Send an invoice attached using secure credentials, with a copy to the collections team:

SMTP Send
host = "smtp.gmail.com"
username = credential("mail-bot")["user"]
password = credential("mail-bot")["password"]
from = "Billing <" + credential("mail-bot")["user"] + ">"
to = customer.email
cc = "collections@company.com"
subject = "Invoice " + invoiceNumber
body = "<p>Please find invoice <b>" + invoiceNumber + "</b> attached. Thank you for your purchase.</p>"
isHtml = true
attachments = arr("C:/invoices/" + invoiceNumber + ".pdf")