# Courier

Mail delivery for Elixir

[![Build Status](](

Courier is an adapter-based mail delivery system for Elixir applications. It depends upon `[Mail](`
for composing the message.

First create your mailer:

defmdodule MyApp.Mailer do
  use Courier, otp_app: :my_app

Next set the default adapter in `config/config.exs` or `config/{environment}.exs`:

config :my_app, MyApp.Mailer,
  adapter: Courier.Adapters.SMTP,
  relay: "",
  hostname: "my-mail-server",
  port: 2525,
  username: System.get_env("COURIER_USERNMAE"),
  password: System.get_env("CORUIER_PASSWORD")

More configuration options for each adapter is in the [Adapters](#Adapter) section.

Then you can compose and deliver the message:

message =
  |> Mail.put_to("")
  |> Mail.put_from("")
  |> Mail.put_subject("How are things?")
  |> Mail.put_text("Let's meet for drinks!")
  |> Mail.put_html("<p>Let's meet for drinks!</p>")


Courier will deliver the message through the adapter that is configured.

## Rendering with Phoenix Views

If you'd like to render the `text` or `html` parts with a Phoenix view
you should use `Courier.render/4`

message =
  |> Mail.put_to("")
  |> Mail.put_from("")
  |> Mail.put_subject("How are things?")
  |> Courier.render(MyApp.MailerView, "check_in.txt", user: user)
  |> Courier.render(MyApp.MailerView, "check_in.html", user: user)


`Courier.render/4` will parse the template path to determine the
expected `content-type`. For example, if your template is `foobar.html`
the assumed `content-type` is `text/html` and Courier will render the
template to a string and use `Mail.put_html(message, rendered_template)`

## Adapters

Courier comes with some built-in adapters

### Courier.Adapters.SMTP

The built-in SMTP adapter is implemented with [`gen_smtp`](


- `relay` mail server host
- `port` mail server port (defaults to `25` when `ssl` is `false`, defaults to `465` when `ssl` is `true`)
- `ssl` connect with SSL (defaults to `false`)
- `hostname` label for the `relay`
- `username` username used for authentication
- `password` password used for authentication

### Courier.Adapters.Logger

Will write deliver all messages to the `Logger`. All attachment encoded data will 
rener as `[File content]`

- `level` the `Logger` level to send the message to (defaults to `:info`)

### Courier.Adapters.ETS

Will store messages in ETS. Includes API for interacting with the messages.

### Courier.Adapters.Test

Exposes the ETS adapter from a REST based API

## Authors ##

* [Brian Cardarella](

[We are very thankful for the many contributors](

## Versioning ##

This library follows [Semantic Versioning](

## Looking for help with your Elixir project? ##

[At DockYard we are ready to help you build your next Elixir project]( We have a unique expertise 
in Elixir and Phoenix development that is unmatched. [Get in touch!](

At DockYard we love Elixir! You can [read our Elixir blog posts](
or come visit us at [The Boston Elixir Meetup]( that we organize.

## Want to help? ##

Please do! We are always looking to improve this library. Please see our
[Contribution Guidelines](
on how to properly submit issues and pull requests.

## Legal ##

[DockYard](, Inc. &copy; 2016


[Licensed under the MIT license](