{"id":21144167,"url":"https://github.com/straw-hat-labs/straw_hat_mailer","last_synced_at":"2025-12-12T00:19:41.314Z","repository":{"id":57553719,"uuid":"101932336","full_name":"straw-hat-labs/straw_hat_mailer","owner":"straw-hat-labs","description":"Email Management","archived":false,"fork":false,"pushed_at":"2019-11-01T11:26:17.000Z","size":5492,"stargazers_count":10,"open_issues_count":10,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-22T22:36:15.558Z","etag":null,"topics":["elixir","elixir-lang","email","email-sender","email-template","mailer","otp"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/straw_hat_mailer","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/straw-hat-labs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-30T21:53:27.000Z","updated_at":"2024-10-28T21:50:10.000Z","dependencies_parsed_at":"2022-09-26T18:50:14.769Z","dependency_job_id":null,"html_url":"https://github.com/straw-hat-labs/straw_hat_mailer","commit_stats":null,"previous_names":["straw-hat-team/straw_hat_mailer"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/straw-hat-labs/straw_hat_mailer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/straw-hat-labs%2Fstraw_hat_mailer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/straw-hat-labs%2Fstraw_hat_mailer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/straw-hat-labs%2Fstraw_hat_mailer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/straw-hat-labs%2Fstraw_hat_mailer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/straw-hat-labs","download_url":"https://codeload.github.com/straw-hat-labs/straw_hat_mailer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/straw-hat-labs%2Fstraw_hat_mailer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264405867,"owners_count":23603028,"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":["elixir","elixir-lang","email","email-sender","email-template","mailer","otp"],"created_at":"2024-11-20T08:08:50.806Z","updated_at":"2025-12-12T00:19:41.282Z","avatar_url":"https://github.com/straw-hat-labs.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StrawHat.Mailer\n\n[![Hex.pm](https://img.shields.io/hexpm/v/straw_hat_mailer.svg)](https://hex.pm/packages/straw_hat_mailer)\n[![CI Status](https://travis-ci.org/straw-hat-team/straw_hat_mailer.svg?branch=master)](https://travis-ci.org/straw-hat-team/straw_hat_mailer)\n[![Code Coverage](https://codecov.io/gh/straw-hat-team/straw_hat_mailer/branch/master/graph/badge.svg)](https://codecov.io/gh/straw-hat-team/straw_hat_mailer)\n\nEmail Management with templating capability. The templates use Mustache template\nunder the hood so you can do everything that the template system allow you to do.\n\n### Configuration\n\nWe need to setup `Swoosh` adapter to be able to send the emails and the database\nfor save the templates.\n\n```elixir\n# In your config files\nconfig :straw_hat_mailer, StrawHat.Mailer,\n  # Swoosh.Adapters.Local for development\n  adapter: Swoosh.Adapters.Sendgrid,\n  api_key: \"SG.x.x\"\n```\n\n## Usage\n\n### Creating the Templates\n\n`StrawHat.Mailer.Template` have all the functionalities for managing the\ntemplates, so check the module for more information.\n\nYou could use `seed.exs` or just use `iex -S mix` for interactive terminal.\n\n```elixir\n{:ok, welcome_template} = StrawHat.Mailer.Template.create_template(%{\n  name: \"welcome\",\n  owner_id: \"system:my_app\",\n  privacy: StrawHat.Mailer.Privacy.public(),\n  title: \"Welcome to My App\",\n\n  subject: \"Welcome to My App\",\n  html: \"\"\"\n  \u003ch1\u003eWelcome to My App {{data.full_name}}\u003c/h1\u003e\n  \"\"\",\n  text: \"\"\"\n  Welcome to My App {{data.full_name}}\n  \"\"\"\n})\n```\n\nYou could also use partials on your template so you could share sections of\nyour email template, most of the time you will use this for the header and footer\nso it is easier to update at any time your templates without much afford.\n\nLet's create the partials.\n\n```elixir\n{:ok, header_partial} = StrawHat.Mailer.Partial.create_partial(%{\n  name: \"company_header\",\n  owner_id: \"system:my_app\",\n  privacy: StrawHat.Mailer.Privacy.public(),\n\n  html: \"\"\"\n   \u003cheader\u003e\n    \u003ch1\u003eMy App\u003c/h1\u003e\n    \u003ch2\u003eThe Tag line\u003c/h2\u003e\n   \u003c/header\u003e\n  \"\"\",\n  text: \"\"\"\n  My header is Awesome\n  The Tag line\n  \"\"\"\n})\n\n{:ok, footer_partial} = StrawHat.Mailer.Partial.create_partial(%{\n  name: \"company_footer\",\n  owner_id: \"system:my_app\",\n  privacy: StrawHat.Mailer.Privacy.public(),\n\n  html: \"\"\"\n   \u003cfooter\u003e\n    \u003cp\u003eContact ACME for bug report BrokeBack\u003c/p\u003e\n   \u003c/footer\u003e\n  \"\"\",\n  text: \"\"\"\n  Contact ACME for bug report BrokeBack\n  \"\"\"\n})\n```\n\nNow we just need to add the partials to the template.\n\n```elixir\n{:ok, welcome_template} =\n  StrawHat.Mailer.Template.get_template_by_name(\"welcome\")\n\nStrawHat.Mailer.Template.add_partials(welcome_template, [\n  header_partial,\n  footer_partial\n])\n```\n\nNow you can start using your partials in your template.\n\n```elixir\n{:ok, welcome_template} =\n  StrawHat.Mailer.Template.get_template_by_name(\"welcome\")\n\nStrawHat.Mailer.Template.update_template(welcome_template, %{\n  html: \"\"\"\n  {{{partials.company_header}}}\n  \u003ch1\u003eWelcome to My App {{data.full_name}}\u003c/h1\u003e\n  {{{partials.footer_header}}}\n  \"\"\",\n  text: \"\"\"\n  {{{partials.company_header}}}\n  Welcome to My App {{data.full_name}}\n  {{{partials.footer_header}}}\n  \"\"\"\n})\n```\n\nAnd you are good to go.\n\n### Sending the Email\n\n`StrawHat.Mailer` uses `Swoosh` under the hood. The next example shows how to create\nan email using specific template.\n\n```elixir\ndefmodule MyApp do\n  def send_welcome_email(to, data) do\n    from = {\"ACME\", \"noreply@acme.com\"}\n\n    response =\n      from\n      |\u003e StrawHat.Mailer.Email.new(to)\n      |\u003e StrawHat.Mailer.Email.with_template(\"welcome\", data)\n\n    case response do\n      {:ok, email} -\u003e StrawHat.Mailer.deliver(email)\n      error -\u003e error\n    end\n  end\nend\n\n# Later on\nto = {\"User Name\", \"user_email@something.com\"}\ndata = %{\n  \"full_name\" =\u003e \"My name is Jeff\"\n}\n\nMyApp.send_welcome_email(to, data)\n```\n\n## Use cases\n\nAll the APIs are contain in the business use cases are under `Use Cases`\ndocumentation section. Check the available modules and the public API.\n\nYou should be able to comprehend the API by reading the type spec and the\nfunction name. Please open an issue or even better make pull request about the\ndocumation if you have any issues with it.\n\n## Migrations\n\nSince this library does not have any repository, it does not run any migration.\nYou will need to handle the migrations on your application that contains the\nrepository.\n\nThe `migrations` directory contains a series of migrations that should cover\nthe common use cases.\n\n\u003e **Note**\n\u003e\n\u003e Each migration module has a `Created at` timestamp, this information is useful\n\u003e to decide when and the order on which the migrations should be run.\n\n### Using migrations\n\nAfter creating an Ecto migration in your project you could call one of the\nmigrations from your `change` callback in your module.\n\n```elixir\ndefmodule MyApp.Repo.Migrations.CreatePartialsTable do\n  use Ecto.Migration\n\n  def change do\n    StrawHat.Mailer.Migrations.CreatePartialsTable.change()\n  end\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstraw-hat-labs%2Fstraw_hat_mailer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstraw-hat-labs%2Fstraw_hat_mailer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstraw-hat-labs%2Fstraw_hat_mailer/lists"}