{"id":13835052,"url":"https://github.com/swoosh/phoenix_swoosh","last_synced_at":"2025-05-14T16:02:41.157Z","repository":{"id":5946198,"uuid":"54292330","full_name":"swoosh/phoenix_swoosh","owner":"swoosh","description":"Swoosh \u003c3 Phoenix","archived":false,"fork":false,"pushed_at":"2025-03-31T15:21:12.000Z","size":461,"stargazers_count":278,"open_issues_count":2,"forks_count":31,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-04T14:49:50.760Z","etag":null,"topics":["elixir","email","phoenix","swoosh"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/phoenix_swoosh","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/swoosh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-19T23:50:01.000Z","updated_at":"2025-04-02T07:10:13.000Z","dependencies_parsed_at":"2023-12-22T00:53:17.110Z","dependency_job_id":"c1780528-9037-4a61-96b0-6cfb899e18e1","html_url":"https://github.com/swoosh/phoenix_swoosh","commit_stats":{"total_commits":330,"total_committers":19,"mean_commits":17.36842105263158,"dds":0.6181818181818182,"last_synced_commit":"4e8c5307dc90e7f7de3d1a07b3099659debbccbd"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoosh%2Fphoenix_swoosh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoosh%2Fphoenix_swoosh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoosh%2Fphoenix_swoosh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swoosh%2Fphoenix_swoosh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swoosh","download_url":"https://codeload.github.com/swoosh/phoenix_swoosh/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247987181,"owners_count":21028891,"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","email","phoenix","swoosh"],"created_at":"2024-08-04T14:00:55.681Z","updated_at":"2025-04-09T06:01:49.980Z","avatar_url":"https://github.com/swoosh.png","language":"Elixir","funding_links":[],"categories":["Elixir"],"sub_categories":[],"readme":"# Phoenix.Swoosh\n\n[![Elixir CI](https://github.com/swoosh/phoenix_swoosh/actions/workflows/elixir.yml/badge.svg)](https://github.com/swoosh/phoenix_swoosh/actions/workflows/elixir.yml)\n[![Module Version](https://img.shields.io/hexpm/v/phoenix_swoosh.svg)](https://hex.pm/packages/phoenix_swoosh)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/phoenix_swoosh/)\n[![Total Download](https://img.shields.io/hexpm/dt/phoenix_swoosh.svg)](https://hex.pm/packages/phoenix_swoosh)\n[![License](https://img.shields.io/hexpm/l/phoenix_swoosh.svg)](https://github.com/swoosh/phoenix_swoosh/blob/master/LICENSE)\n[![Last Updated](https://img.shields.io/github/last-commit/swoosh/phoenix_swoosh.svg)](https://github.com/swoosh/phoenix_swoosh/commits/master)\n\n`Phoenix.View` + `Swoosh`. ([Discuss about the future post-Phoenix-1.7 here](https://github.com/swoosh/phoenix_swoosh/issues/287))\n\nThis module provides the ability to set the HTML and/or text body of an email by rendering templates.\n\n## Installation\n\nAdd `:phoenix_swoosh` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:phoenix_swoosh, \"~\u003e 1.0\"},\n\n    # without phoenix_html, phoenix_swoosh only works with plain text templates\n    # if you want to use HTML templates\n    # {:phoenix_html, \"~\u003e 3.0\"},\n  ]\nend\n```\n\nYou probably also want to install [`finch`](https://hex.pm/packages/finch),\n[`hackney`](https://hex.pm/packages/hackney) or an HTTP client of your own choice,\nif you are using a provider that `Swoosh` talks to via their HTTP API.\n\nOr [`:gen_smtp`](https://hex.pm/packages/gen_smtp) if you are working with a provider\nthat only works through SMTP.\n\nSee `Swoosh` for more details.\n\n## Usage\n\n### 1. Classic setup\n\nSetting up the templates:\n\n```eex\n# path_to/templates/user_notifier/welcome.html.eex\n\u003cdiv\u003e\n  \u003ch1\u003eWelcome to Sample, \u003c%= @name %\u003e!\u003c/h1\u003e\n\u003c/div\u003e\n```\n\n```elixir\n# path_to/views/user_notifier_view.ex\ndefmodule Sample.UserNotifierView do\n  use Phoenix.View, root: \"path_to/templates\"\nend\n```\n\nPassing values to templates:\n\n```elixir\n# path_to/notifiers/user_notifier.ex\ndefmodule Sample.UserNotifier do\n  use Phoenix.Swoosh, view: Sample.UserNotifierView\n\n  def welcome(user) do\n    new()\n    |\u003e from(\"tony@stark.com\")\n    |\u003e to(user.email)\n    |\u003e subject(\"Hello, Avengers!\")\n    |\u003e render_body(\"welcome.html\", %{name: name})\n  end\nend\n```\n\nMaybe with a layout:\n\n```eex\n# path_to/templates/layout/email.html.eex\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003e\u003c%= @email.subject %\u003e\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003c%= @inner_content %\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n```elixir\ndefmodule Sample.LayoutView do\n  use Phoenix.View, root: \"path_to/templates\"\nend\n```\n\n```elixir\n# path_to/notifiers/user_notifier.ex\ndefmodule Sample.UserNotifier do\n  use Phoenix.Swoosh,\n    view: Sample.NotifierView,\n    layout: {Sample.LayoutView, :email}\n\n  # ... same welcome ...\nend\n```\n\nLayout can also be added/changed dynamically with `put_new_layout/2` and `put_layout/2`\n\n### 2. Standalone setup\n\n```eex\n# path_to/templates/user_notifier/welcome.html.eex\n\u003cdiv\u003e\n  \u003ch1\u003eWelcome to Sample, \u003c%= @name %\u003e!\u003c/h1\u003e\n\u003c/div\u003e\n```\n\n```elixir\n# path_to/notifiers/user_notifier.ex\ndefmodule Sample.UserNotifier do\n  use Phoenix.Swoosh,\n    template_root: \"path_to/templates\",\n    template_path: \"user_notifier\"\n\n  # ... same welcome ...\nend\n```\n\nIn this setup, the notifier module itself serves as the view module\n\n`template_root`, `template_path` and `template_namespace`\nwill be passed to `Phoenix.View` as `root`, `path` and `namespace`.\n\nLayout can be setup the same way as classic setup.\n\n## Customization\n\nWhen using either the classic or standalone setup described above, the\nextensions of the templates used can be customized. For example, let's say\nMJML is the desired markup language to use for HTML emails, and there's a\ntemplate such as:\n\n```eex\n# path_to/templates/user_notifier/welcome.mjml.eex\n\n\u003cmjml\u003e\n  \u003cmj-body\u003e\n    \u003cmj-text\u003eWelcome to Sample, \u003c%= @name %\u003e!\u003c/mj-text\u003e\n  \u003c/mj-body\u003e\n\u003c/mjml\u003e\n```\n\nPhoenix.Swoosh can be configured to use the \"mjml\" extension when rendering the\nHTML body of the email:\n\n```elixir\n# path_to/notifiers/user_notifier.ex\ndefmodule Sample.UserNotifier do\n  use Phoenix.Swoosh,\n    formats: %{\"mjml\" =\u003e :html_body, \"text\" =\u003e :text_body}\n\n  # ... same welcome as above ...\nend\n```\n\nThis requires that Phoenix knows how to handle templates using the \"mjml\"\nformat. This can be done by creating a module that exports\n`encode_to_iodata!/1`:\n\n```elixir\ndefmodule Sample.Mjml do\n  def encode_to_iodata!(mjml) do\n    with {:ok, html} \u003c- Mjml.to_html(mjml) do\n      html\n    end\n  end\nend\n```\n\nAnd then configuring Phoenix to use it:\n\n```elixir\nconfig :phoenix, format_encoders: [mjml: Sample.Mjml]\n```\n\nThe above example is using [`mjml`](https://hex.pm/packages/mjml), which would\nneed to be installed as well.\n\n## Copyright and License\n\nCopyright (c) 2021 Swoosh contributors\n\nReleased under the MIT License, which can be found in [LICENSE.md](./LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswoosh%2Fphoenix_swoosh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswoosh%2Fphoenix_swoosh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswoosh%2Fphoenix_swoosh/lists"}