ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - KamilLelonek/ex_postmark: Postmark adapter for sending template emails in Elixir
Postmark adapter for sending template emails in Elixir - KamilLelonek/ex_postmark
Visit Site

GitHub - KamilLelonek/ex_postmark: Postmark adapter for sending template emails in Elixir

GitHub - KamilLelonek/ex_postmark: Postmark adapter for sending template emails in Elixir

ex_postmark

Build Status

This is a library inspired by swoosh for Postmark service to send template emails.

Installation

If available in Hex, the package can be installed as:

  1. Add ex_postmark to your list of dependencies in mix.exs:
def deps do
  [{:ex_postmark, "~> 1.x.x"}]
end
  1. Ensure ex_postmark is started before your application:
def application do
  [applications: [:ex_postmark]]
end

Usage

You will need to prepare a couple of files to make ex_postmark working.

Config

Here is the way how to prepare specific config files:

Development

# config/dev.ex

config :your_application, YourApplication.Mailer,
  adapter: ExPostmark.Adapters.Local

You can access all sent emails using convenient ExPostmark.Adapters.Local.Storage functions.

Tests

# config/test.ex

config :your_application, YourApplication.Mailer,
  adapter: ExPostmark.Adapters.Test

You can access the recent sent email as:

assert_received {:email, email}

Production

# config/prod.ex

config :your_application, YourApplication.Mailer,
  adapter:        ExPostmark.Adapters.Postmark,
  server_api_key: System.get_env("POSTMARK_SERVER_API_KEY")

Emails are being sent using regular Postmark platform.

Mailer

Next, you have to prepare a corresponding mailer:

# your_application/mailer.ex

defmodule YourApplication.Mailer do
	use ExPostmark.Mailer, otp_app: :your_application
end

Note that otp_app represents the configured name.

Creating an email

Firstly, you have to prepare an email. You can do that in two ways:

1. Using new/1 constructor

Email.new(
  from:           {"From", "[email protected]"},
  to:             "[email protected]",
  cc:             ["[email protected]", {"CC2", "[email protected]"}],
  bcc:            "[email protected]",
  reply_to:       "[email protected]",
  headers:        %{"X-Accept-Language" => "pl"},
  template_id:    1,
  template_model: %{name: "name", team: "team"}
)

2. Using builder functions

email = Email.new()
      |> Email.to("[email protected]")
      |> Email.cc("[email protected]")
      |> Email.bcc("[email protected]")
      |> Email.template_id(123)
      |> Email.put_template_model(:name, "Name")
      |> Email.put_template_model(:team, "Team")

All functions are available in docs.

Sending an email

Once you have an Email prepared, you can use your predefined Mailer to send it:

YourApplication.Mailer.deliver(emai)

And that's it, your email should be sent.

A note about subjects:

There is a way to set a subject for your email using a template, but it's not done out of the box. You need to make sure to add an additional variable subject for your template model and then put it in a place of a Subject line.

Here is the final configuration:

Postmark subject

Later on, you can use subject in a convenient method like:

email = Email.new()
      |> Email.subject("[email protected]")
      # ...

but don't be confused, as it's not a regular way to put a custom subject.

Tests

To run all tests, execute:

mix test

Keep in mind that the default command will skip integration tests. To include them, run:

mix test --include integration

For integration test make sure you have the following vairables exported in your environment:

  • POSTMARK_SERVER_API_KEY - Server API token required for authentication from Postmark server credentials
  • POSTMARK_EMAIL_FROM - your verified sender signature in Postmark
  • POSTMARK_EMAIL_TO - any existing recipient email
  • POSTMARK_TEMPLATE_ID - an ID of configured template in Postmark

Contributing

  1. Fork the repository and then clone it locally:
git clone https://github.com/KamilLelonek/ex_postmark
  1. Create a topic branch for your changes:
git checkout -b fix-mailchimp-pricing-bug
  1. Commit a failing test for the bug:
git commit -am "Adds a failing test that demonstrates the bug"
  1. Commit a fix that makes the test pass:
git commit -am "Adds a fix for the bug"
  1. Run the tests:
mix test
  1. If everything looks good, push to your fork:
git push origin fix-mailchimp-pricing-bug
  1. Submit a pull request.

Documentation

Documentation is written into the library, you will find it in the source code, accessible from iex and of course, it all gets published to hexdocs.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory