• Stars
    star
    194
  • Rank 200,186 (Top 4 %)
  • Language
    Elixir
  • License
    MIT License
  • Created about 10 years ago
  • Updated about 2 years 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,401
star
2

phoenix_chat_example

JavaScript
688
star
3

phoenix_live_view_example

Elixir
537
star
4

todo_trek

Elixir
367
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
158
star
9

single_file_phx_bumblebee_ml

Elixir
93
star
10

dot_emacs

evil-mode
Emacs Lisp
93
star
11

elixirconf_training

JavaScript
74
star
12

single_file_phoenix_fly

Elixir
58
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

fly_ollama

Dockerfile
10
star
22

ex_copter

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

phoenix_takes_flight

CSS
9
star
24

metrics

Elixir
8
star
25

blinky_presence

Phoenix Presence with Nerves example
Elixir
8
star
26

file_presenter

Elixir
6
star
27

gitit

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

bclose.vim

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

riak_tasks

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

rumbl-example

Elixir
5
star
31

phoenix_brunch_vue

Elixir
5
star
32

pubsub_stress

JavaScript
5
star
33

phlux

JavaScript
4
star
34

sublime-files

Sublime Text 2 settings and packages
3
star
35

fly_yugabyte

Shell
3
star
36

hex_issue_example

Elixir
2
star
37

phoenix_pubsub_federation

Elixir
2
star
38

coffeekup_rails

Ruby
2
star
39

phoenix_render_example

Elixir
2
star
40

phoenix_federation_server

Elixir
2
star
41

fishcakez_channel_example

Elixir
2
star
42

historian

Ruby
1
star
43

validate

Coffeescript client-side validation library
CoffeeScript
1
star
44

phoenix_debugger_bug

Elixir
1
star
45

riaktor

Coming soon
1
star
46

live_eex

Elixir
1
star
47

my_plug

Elixir
1
star
48

chrismccord.com-old-

JavaScript
1
star
49

dotfiles

Shell
1
star