Use SMTP accounts #
In this tutorial, you will learn how to implement the SMTP configuration for notifications to be able to send emails from a default or custom account.
You can define an SMTP default account that will be use by the app to send SMTP notifications. You can also define a custom SMTP account for each tenant.
Configuration #
Using kuzzlerc #
Setup #
Add this configuration to your kuzzlerc :
{
"application": {
"smtp": {
"passwordEncryptionKey": "s0meL0ngStr|ngTh@tC@@ntBeCr@ck€d",
"defaultAccountPassword": "P@$$word"
}
}
}
Using Vault #
Prerequisites #
- Create a Vault key for your project for each environment.
- Create a
secrets.json
file in theapps/api/<environment>
folder. - Setup the following environment variables:
KUZZLE_VAULT_KEY
KUZZLE_SECRETS_FILE
KUZZLE_USERNAME
KUZZLE_PASSWORD
Setup #
You need to use the app's Kuzzle Vault with the following config:
// secrets.json
{
"smtp": {
// password used for default SMTP account
"defaultAccountPassword": "p@$$w0rd",
// this key will be used to encrypt the tenant's SMTP secrets in the database
"passwordEncryptionKey": "s0meL0ngStr|ngTh@tC@@ntBeCr@ck€d"
}
}
The decrypted secrets.json
file must not be versioned directly, you need to encrypt it with the Vault key using Kourou beforehand:
cd apps/api/<environment>
# create secrets.enc.json
kourou vault:encrypt ./secrets.json
Store the default account configuration #
To store your default account config, you can use Kourou (the password needs to be set in the Vault secrets):
- Setup the following environment variables:
KUZZLE_VAULT_KEY
KUZZLE_SECRETS_FILE
KUZZLE_USERNAME
KUZZLE_PASSWORD
KUZZLE_HOST
KUZZLE_PORT
kourou hermes/config:updateDefaultAccount -a client=smtp --body='{"host": "<host>", "port": <port>, "user": "<smtpUser>", "defaultSender": "<smtpDefaultSenderAdress>"}'
Update a tenants custom account #
This configuration is accessible from the user interface for administrators in the IoT Platform frontend (Administration/Notification/SMTP), but you can also set it up with Kourou:
- Setup the following environment variables:
KUZZLE_VAULT_KEY
KUZZLE_SECRETS_FILE
KUZZLE_USERNAME
KUZZLE_PASSWORD
KUZZLE_HOST
KUZZLE_PORT
kourou hermes/config:updateCustomAccount -a client=smtp --body='{"host": "<host>", "port": <port>, "user": "<smtpUser>", "defaultSender": "<smtpDefaultSenderAdress>", "tenantId": "tenant-air_quality-test", "password": "<password>"}'