Skip to main content

$mail.send

This method sends an email message and passes the SMTP server settings.

tip
If there is more than one place in your script where you send emails, you can use the more simple $mail.sendMessage method.

Syntax

The method accepts an object with the following properties:

PropertyTypeRequiredDescription
smtpHostStringYesSMTP server host.
smtpPortNumberNoSMTP server port. The default value is 25.
userStringYesSMTP server user.
passwordStringYesSMTP server password.
fromStringYesEmail sender.
hiddenCopyString or string arrayNoEmail hidden copy recipient or list of recipients.
toString or string arrayYesEmail recipient or list of recipients.
subjectStringNoMessage subject.
contentStringYesMessage body. You can use HTML markup within it.
sslEnabledBooleanNoWhether the SMTP server uses implicit TLS encryption (SSL). If true, the server port is usually 465. The default value is false.
tlsEnabledBooleanNoWhether the SMTP server uses explicit TLS encryption. If true, the server port is usually 587. The default value is false.
$mail.send({
smtpHost: "smtp.just-ai.com",
smtpPort: 587,
user: "user@just-ai.com",
password: $secrets.get("smtpPassword"),
from: "bot@just-ai.com",
hiddenCopy: ["admin@just-ai.com", "support@just-ai.com"],
to: ["user@example.com", "client@example.com"],
subject: "We have a unique offer just for you!",
content: "March 25 only, 20% off all our business plans!"
sslEnabled: false,
tlsEnabled: true
});

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

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.send({
smtpHost: "smtp.just-ai.com",
smtpPort: 2525,
user: "user@just-ai.com",
password: $secrets.get("smtpPassword"),
from: "bot@just-ai.com",
to: "user@example.com",
subject: "Data processing agreement",
content: "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.