This document describes how to configure and send email from a CB app.
For simple applications, there is no need to configure anything. Chicago Boss will attempt to deliver mail directly to the recipient. However, if the recipient’s mail server is down, the message might be lost, so you might want to configure a separate SMTP server (such as Postfix).
To specify an SMTP relay, use the mail_relay
configuration option, which should be a string with the SMTP server name.
The mail-sending API is described in the API docs.
This example sends a simple welcome message using a template.
mail/view/test_message.txt:
Hello, {{ name }}! Welcome to the site.
mail/mail_controller.erl:
test_message(Name, Email) ->
Headers = [{"Subject", "Welcome!"}, {"To", Email}, {"From", "[email protected]"}},
{ok, "[email protected]", Email, Headers, [{name, Name}]}.
With these two files in place, we can now send this message from anywhere in the CB app with the following invocation:
boss_mail:send(test_message, ["Johhny", "[email protected]"])
And [email protected] will receive:
From: [email protected] To: [email protected] Subject: Welcome! Hello, Johnny! Welcome to the site.