$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:
Property | Type | Required | Description |
---|---|---|---|
smtpHost | String | Yes | SMTP server host. |
smtpPort | Number | No | SMTP server port. The default value is 25. |
user | String | Yes | SMTP server user. |
password | String | Yes | SMTP server password. |
from | String | Yes | Email sender. |
hiddenCopy | String or string array | No | Email hidden copy recipient or list of recipients. |
to | String or string array | Yes | Email recipient or list of recipients. |
subject | String | No | Message subject. |
content | String | Yes | Message body. You can use HTML markup within it. |
sslEnabled | Boolean | No | Whether the SMTP server uses implicit TLS encryption (SSL). If true , the server port is usually 465. The default value is false . |
tlsEnabled | Boolean | No | Whether 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.