The $mail
built-in service allows sending email messages from the bot script.
caution
To use the
$email
service, you will need a mail server implementing the SMTP protocol.
You can try ready-to-use cloud solutions or run your own server.Another option to send email messages is to use the Email
action tag: it doesn’t require you to configure a mail server.
However, all messages will have as their sender.
Methods
Method | Description |
---|---|
config | Configure the SMTP server settings. |
debug | Enable or disable the $mail service debug mode. |
send | Send an email message and pass the SMTP server settings. |
sendMessage | Send an email message via the pre-configured SMTP server. |
SMTP server configuration
When your server is ready to use, you need to provide its settings in the script. This can be done in several ways:
-
In the
injector.smtp
section of thechatbot.yaml
file. It sets the same configuration for ECMAScript 5 and ECMAScript 6. -
Using the
$mail.config
method.cautionDepending on how you call the method, it can set the configuration:
- for ECMAScript 5 and ECMAScript 6 at the same time;
- for one of these runtimes only.
-
Simultaneously with sending an email, using the
$mail.send
method.
- chatbot.yaml
- $mail.config
- $mail.send
injector:
smtp:
host: smtp.tovie.ai # SMTP server host
port: 2525 # SMTP server port
user: user@tovie.ai # SMTP server user
password: qwerty # SMTP server password
from: bot@tovie.ai # Email sender
# Optional properties
hiddenCopy: admin@tovie.ai # Email hidden copy recipient
# You can specify a list of recipients:
# hiddenCopy:
# - admin@tovie.ai
# - support@tovie.ai
debugMode: true # Whether debug mode is on or off
$mail.config(
"smtp.tovie.ai", // Host
2525, // Port
"user@tovie.ai", // User
$secrets.get("smtpPassword"), // Password
"bot@tovie.ai", // Sender
"admin@tovie.ai" // Hidden copy recipient
);
$mail.send({
smtpHost: $env.get("smtpHost"),
smtpPort: $env.get("smtpPort"),
user: $env.get("smtpUser"),
password: $secrets.get("smtpPassword"),
from: "bot@tovie.ai",
hiddenCopy: "admin@tovie.ai",
to: "user@example.com",
subject: "Message subject",
content: "Message body"
});
tip
The recommended way to provide the settings is to use the
$mail
methods instead of chatbot.yaml
.
This allows you to store them separately from the script as secrets and variables rather than in the source code.
You will be able to modify the settings easily without changing the code, and sensitive data will be more secure.