Skip to main content

$mail.sendMessage

This method sends an email message via a pre-configured SMTP server.

Server configuration

Before you use this method, make sure you have configured the SMTP server settings via chatbot.yaml or the $mail.config method.

The $mail.sendMessage method uses the configuration from the runtime where it is called:

  • In the script tag, it uses the configuration for ECMAScript 5.
  • In the scriptEs6 tag, it uses the configuration for ECMAScript 6.

Syntax

The method accepts three arguments:

ArgumentDescription
addressString or string arrayEmail recipient or list of recipients.
subjectStringMessage subject.
bodyStringMessage body. You can use HTML markup within it.
$mail.sendMessage(
"user@example.com",
"We have a unique offer just for you!",
"March 25 only, 20% off all our business plans!"
);

The method returns an object with the message delivery status property:

  • OK — the message was sent successfully.
  • UNABLE_TO_CONNECT — SMTP server connection failed.
  • INCORRECT_ADDRESS — an empty string was specified as the sender or recipient address.

How to use

init:
$mail.config(
"smtp.tovie.ai",
2525,
"user@tovie.ai",
$secrets.get("smtpPassword"),
"bot@tovie.ai"
);

theme: /

state: AttachDocument
InputFile:
prompt = Please upload the filled out data processing agreement to the chat.
varName = fileUrl
then = /SendDocument

state: SendDocument
script:
$temp.mailResult = $mail.sendMessage(
"user@example.com",
"Data processing agreement",
"Hello! Please find the filled out agreement attached to this message or use this <a href=\"" + $session.fileUrl + "\">link</a>."
);
if: $temp.mailResult.status === "OK"
a: The agreement has been successfully sent to the manager.
else:
a: Sorry, email delivery failed.