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
configuration file. - Using the
$mail.config
method. - Simultaneously with sending an email, using the
$mail.send
method.
- chatbot.yaml
- $mail.config
- $mail.send
injector:
smtp:
host: smtp.just-ai.com # SMTP server host
port: 2525 # SMTP server port
user: user@just-ai.com # SMTP server user
password: qwerty # SMTP server password
from: bot@just-ai.com # Email sender
# Optional properties
hiddenCopy: admin@just-ai.com # Email hidden copy recipient
# You can specify a list of recipients:
# hiddenCopy:
# - admin@just-ai.com
# - support@just-ai.com
debugMode: true # Whether debug mode is on or off
$mail.config(
"smtp.just-ai.com", // Host
2525, // Port
"user@just-ai.com", // User
$secrets.get("smtpPassword"), // Password
"bot@just-ai.com", // Sender
"admin@just-ai.com" // Hidden copy recipient
);
$mail.send({
smtpHost: $env.get("smtpHost"),
smtpPort: $env.get("smtpPort"),
user: $env.get("smtpUser"),
password: $secrets.get("smtpPassword"),
from: "bot@just-ai.com",
hiddenCopy: "admin@just-ai.com",
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.