Mailer v1.3.0 Mailer
A simple SMTP mailer.
This can be used to send one off emails such welcome emails after signing up to a service or password recovery emails.
What it is not
A mass mailer, just don’t do it.
Example usage
First compose an email with
email = Mailer.compose_email(from: "from@example.com",
to: "to@example.com",
subject: "Subject",
template: "welcome_template",
data: template_data)
Then send the email with
response = Mailer.send(email)
The response can be checked for failed deliveries.
Summary
Functions
Compose an email to a recipient
Compose an email to a recipient
Send a composed, email to the recipient
Functions
Specs
compose_email([{atom, term}]) ::
Email.Plain.t |
Email.Multipart.t
Compose an email to a recipient.
The keyword list must contain the following parameters:
:from
, :to
, :subject
, :template
, :data
.
The following parameters are optional:
:country_code
Default parameters can be specified in the application config:
config :mailer,
common_mail_params: [from: "Example <noreply@example.com>"]
Given the that the templates are located in the location:
priv/templates
if the compose_email is called with a template named ‘plain’ it will look for the templates ‘plain.txt’ and ‘plain.html’ in location
priv/templates/plain/
If the template resolves to a single .txt file it will send a plain text email.
If the template resolves to both .html and a .txt file it will send a multipart email.
The template location can be internationalised by passing an optional country code. For example passing a country code of ‘en’ will modify the search path to:
priv/templates/plain/en/
Compose an email to a recipient.
Similar to compose_email/1, but with parameters supplied directly. Ignores default parameters from the application config.