Skip to content

Latest commit

 

History

History
45 lines (29 loc) · 1.36 KB

Sending-Email.textile

File metadata and controls

45 lines (29 loc) · 1.36 KB

This document describes how to configure and send email from a CB app.

Configuration

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.

API

The mail-sending API is described in the API docs.

Example

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", "site@example.com"}},
    {ok, "site@example.com", 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", "johnny@example.com"])

And johnny@example.com will receive:

From: site@example.com
To: johnny@example.com
Subject: Welcome!

Hello, Johnny! Welcome to the site.