{"id":13507838,"url":"https://github.com/KamilLelonek/ex_postmark","last_synced_at":"2025-03-30T09:33:06.892Z","repository":{"id":62429384,"uuid":"71369836","full_name":"KamilLelonek/ex_postmark","owner":"KamilLelonek","description":"Postmark adapter for sending template emails in Elixir","archived":false,"fork":false,"pushed_at":"2020-06-18T05:20:12.000Z","size":46,"stargazers_count":4,"open_issues_count":1,"forks_count":5,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-16T01:34:45.167Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://postmarkapp.com/blog/special-delivery-postmark-templates","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KamilLelonek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-19T15:10:14.000Z","updated_at":"2023-10-16T06:55:31.000Z","dependencies_parsed_at":"2022-11-01T20:05:57.330Z","dependency_job_id":null,"html_url":"https://github.com/KamilLelonek/ex_postmark","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KamilLelonek%2Fex_postmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KamilLelonek%2Fex_postmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KamilLelonek%2Fex_postmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KamilLelonek%2Fex_postmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KamilLelonek","download_url":"https://codeload.github.com/KamilLelonek/ex_postmark/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246301963,"owners_count":20755512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:40.625Z","updated_at":"2025-03-30T09:33:06.614Z","avatar_url":"https://github.com/KamilLelonek.png","language":"Elixir","funding_links":[],"categories":["Email"],"sub_categories":[],"readme":"# ex_postmark\n\n[![Build Status](https://travis-ci.org/KamilLelonek/ex_postmark.svg?branch=master)](https://travis-ci.org/KamilLelonek/ex_postmark)\n\nThis is a library inspired by [`swoosh`](https://github.com/swoosh/swoosh) for [Postmark](https://postmarkapp.com/) service to send [template emails](http://developer.postmarkapp.com/developer-api-templates.html#email-with-template).\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed as:\n\n  1. Add `ex_postmark` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:ex_postmark, \"~\u003e 1.x.x\"}]\nend\n```\n\n  2. Ensure `ex_postmark` is started before your application:\n\n```elixir\ndef application do\n  [applications: [:ex_postmark]]\nend\n```\n\n## Usage\n\nYou will need to prepare a couple of files to make `ex_postmark` working.\n\n### Config\n\nHere is the way how to prepare specific config files:\n\n**Development**\n\n```elixir\n# config/dev.ex\n\nconfig :your_application, YourApplication.Mailer,\n  adapter: ExPostmark.Adapters.Local\n```\n\nYou can access all sent emails using [convenient `ExPostmark.Adapters.Local.Storage` functions](https://hexdocs.pm/ex_postmark/ExPostmark.Adapters.Local.Storage.html#functions).\n\n**Tests**\n\n```elixir\n# config/test.ex\n\nconfig :your_application, YourApplication.Mailer,\n  adapter: ExPostmark.Adapters.Test\n```\n\nYou can access the recent sent email as:\n\n```elixir\nassert_received {:email, email}\n```\n\n**Production**\n\n```elixir\n# config/prod.ex\n\nconfig :your_application, YourApplication.Mailer,\n  adapter:        ExPostmark.Adapters.Postmark,\n  server_api_key: System.get_env(\"POSTMARK_SERVER_API_KEY\")\n```\n\nEmails are being sent using regular Postmark platform.\n\n### Mailer\n\nNext, you have to prepare a corresponding mailer:\n\n```elixir\n# your_application/mailer.ex\n\ndefmodule YourApplication.Mailer do\n\tuse ExPostmark.Mailer, otp_app: :your_application\nend\n```\n\nNote that `otp_app` represents the configured name.\n\n### Creating an email\n\nFirstly, you have to prepare an email. You can do that in two ways:\n\n**1. Using `new/1` constructor**\n\n```elixir\nEmail.new(\n  from:           {\"From\", \"from@example.com\"},\n  to:             \"to@example.com\",\n  cc:             [\"cc1@example.com\", {\"CC2\", \"cc1@example.com\"}],\n  bcc:            \"bcc@example.com\",\n  reply_to:       \"reply_to@example.com\",\n  headers:        %{\"X-Accept-Language\" =\u003e \"pl\"},\n  template_id:    1,\n  template_model: %{name: \"name\", team: \"team\"}\n)\n```\n\n**2. Using builder functions**\n\n```elixir\nemail = Email.new()\n      |\u003e Email.to(\"foo.bar@example.com\")\n      |\u003e Email.cc(\"foo.bar@example.com\")\n      |\u003e Email.bcc(\"foo.bar@example.com\")\n      |\u003e Email.template_id(123)\n      |\u003e Email.put_template_model(:name, \"Name\")\n      |\u003e Email.put_template_model(:team, \"Team\")\n```\n\nAll functions are available in [docs](https://hexdocs.pm/ex_postmark/ExPostmark.Email.html#functions).\n\n### Sending an email\n\nOnce you have an `Email` prepared, you can use your predefined `Mailer` to send it:\n\n```elixir\nYourApplication.Mailer.deliver(emai)\n```\n\nAnd that's it, your email should be sent.\n\n**A note about subjects:**\n\nThere 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`.\n\nHere is the final configuration:\n\n![Postmark subject](https://monosnap.com/file/MUem7zVYzB75Oh64FgOUkxGQG98tRZ.png)\n\nLater on, you can use subject in a convenient method like:\n\n```elixir\nemail = Email.new()\n      |\u003e Email.subject(\"foo.bar@example.com\")\n      # ...\n```\n\nbut don't be confused, as it's not a regular way to put a custom subject.\n\n## Tests\n\nTo run all tests, execute:\n\n    mix test\n\nKeep in mind that the default command will skip integration tests. To include them, run:\n\n    mix test --include integration\n\nFor integration test make sure you have the following vairables exported in your environment:\n\n- `POSTMARK_SERVER_API_KEY ` - Server API token required for authentication from Postmark server credentials\n- `POSTMARK_EMAIL_FROM ` - your verified sender signature in Postmark\n- `POSTMARK_EMAIL_TO ` - any existing recipient email\n- `POSTMARK_TEMPLATE_ID ` - an ID of configured template in Postmark\n\n## Contributing\n\n1. [Fork the repository](https://github.com/KamilLelonek/ex_postmark) and then clone it locally:\n\n  ```bash\n  git clone https://github.com/KamilLelonek/ex_postmark\n  ```\n\n2. Create a topic branch for your changes:\n\n  ```bash\n  git checkout -b fix-mailchimp-pricing-bug\n  ```\n\n3. Commit a failing test for the bug:\n\n  ```bash\n  git commit -am \"Adds a failing test that demonstrates the bug\"\n  ```\n\n4. Commit a fix that makes the test pass:\n\n  ```bash\n  git commit -am \"Adds a fix for the bug\"\n  ```\n\n5. Run the tests:\n\n  ```bash\n  mix test\n  ```\n\n6. If everything looks good, push to your fork:\n\n  ```bash\n  git push origin fix-mailchimp-pricing-bug\n  ```\n\n7. [Submit a pull request.](https://help.github.com/articles/creating-a-pull-request)\n\n## Documentation\n\nDocumentation 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](https://hexdocs.pm/ex_postmark).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKamilLelonek%2Fex_postmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKamilLelonek%2Fex_postmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKamilLelonek%2Fex_postmark/lists"}