• Stars
    star
    193
  • Rank 194,028 (Top 4 %)
  • Language
    Elixir
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Elixir Mailgun Client

Elixir Mailgun Client Build Status

# config/config.exs

config :my_app, mailgun_domain: "https://api.mailgun.net/v3/mydomain.com",
                mailgun_key: "key-##############"


# lib/mailer.ex
defmodule MyApp.Mailer do
  @config domain: Application.get_env(:my_app, :mailgun_domain),
          key: Application.get_env(:my_app, :mailgun_key)
  use Mailgun.Client, @config
                      

  @from "[email protected]"

  def send_welcome_text_email(user) do
    send_email to: user.email,
               from: @from,
               subject: "hello!",
               text: "Welcome!"
  end

  def send_welcome_html_email(user) do
    send_email to: user.email,
               from: @from,
               subject: "hello!",
               html: "<strong>Welcome!</strong>"
  end

 # attachments expect a list of maps. Each map should have a filename and path/content

  def send_greetings(user, file_path) do
    send_email to: user.email,
               from: @from,
               subject: "Happy b'day",
               html: "<strong>Cheers!</strong>",
               attachments: [%{path: file_path, filename: "greetings.png"}]
  end

  def send_invoice(user) do
    pdf = Invoice.create_for(user) # a string
    send_email to: user.email,
               from: @from,
               subject: "Invoice",
               html: "<strong>Your Invoice</strong>",
               attachments: [%{content: pdf, filename: "invoice.pdf"}]
  end
end


iex> MyApp.Mailer.send_welcome_text_email(user)
{:ok, ...}

Installation

Add mailgun to your mix.exs dependencies:

def deps do
  [ {:mailgun, "~> 0.1.2"} ]
end

Test mode

For testing purposes mailgun can output emails to a local file instead of actually sending them. Just set the mode configuration key to :test and the test_file_path to where you want that file to appear.

# lib/mailer.ex
defmodule MyApp.Mailer do
  @config domain: Application.get_env(:my_app, :mailgun_domain),
          key: Application.get_env(:my_app, :mailgun_key),
          mode: :test,
          test_file_path: "/tmp/mailgun.json"
  use Mailgun.Client, @config

...
end

httpc options

Under the hood the client uses httpc to call Mailgun REST API. You can inject any valid httpc options to your outbound requests by defining them within httpc_opts config entry:

# lib/mailer.ex
defmodule MyApp.Mailer do
  @config domain: Application.get_env(:my_app, :mailgun_domain),
          key: Application.get_env(:my_app, :mailgun_key),
          httpc_opts: [connect_timeout: 2000, timeout: 3000]
  use Mailgun.Client, @config
...

More Repositories

1

render_sync

Real-time Rails Partials
Ruby
1,398
star
2

phoenix_chat_example

JavaScript
680
star
3

phoenix_live_view_example

Elixir
534
star
4

todo_trek

Elixir
317
star
5

elixir_express

Elixir
283
star
6

labrador

A loyal data retriever for your Rails development databases.
CSS
254
star
7

atlas

Object Relational Mapper for Elixir
Elixir
214
star
8

phoenix_haml

Phoenix Template Engine for Haml
Elixir
156
star
9

dot_emacs

evil-mode
Emacs Lisp
94
star
10

single_file_phx_bumblebee_ml

Elixir
91
star
11

elixirconf_training

JavaScript
73
star
12

single_file_phoenix_fly

Elixir
55
star
13

sketchpad

Elixir
42
star
14

channelsac

Ruby
31
star
15

sync_example

Ruby
24
star
16

phoenix_vs_rails_showdown

Ruby
22
star
17

phoenix_presence_example

Elixir
14
star
18

semantic-ui-brunch-phoenix

Elixir
13
star
19

phoenix_brunch_react

Elixir
11
star
20

dot_vim

Vim Script
11
star
21

ex_copter

Elixir client for the Parrot AR 2.0 Quadcopter
Elixir
10
star
22

phoenix_takes_flight

CSS
9
star
23

metrics

Elixir
8
star
24

blinky_presence

Phoenix Presence with Nerves example
Elixir
8
star
25

file_presenter

Elixir
6
star
26

gitit

Introspect project directory and launch browser to github repo page
CoffeeScript
6
star
27

bclose.vim

Delete a buffer without closing the window
Vim Script
6
star
28

riak_tasks

Simple riak cluster bootstrap and management for dev and test environments
Elixir
5
star
29

rumbl-example

Elixir
5
star
30

pubsub_stress

JavaScript
5
star
31

phoenix_brunch_vue

Elixir
5
star
32

phlux

JavaScript
4
star
33

sublime-files

Sublime Text 2 settings and packages
3
star
34

hex_issue_example

Elixir
2
star
35

phoenix_pubsub_federation

Elixir
2
star
36

coffeekup_rails

Ruby
2
star
37

phoenix_render_example

Elixir
2
star
38

phoenix_federation_server

Elixir
2
star
39

fishcakez_channel_example

Elixir
2
star
40

historian

Ruby
1
star
41

validate

Coffeescript client-side validation library
CoffeeScript
1
star
42

dotfiles

Shell
1
star
43

phoenix_debugger_bug

Elixir
1
star
44

riaktor

Coming soon
1
star
45

live_eex

Elixir
1
star
46

my_plug

Elixir
1
star
47

chrismccord.com-old-

JavaScript
1
star