{"id":2655,"date":"2018-06-01T14:49:34","date_gmt":"2018-06-01T05:49:34","guid":{"rendered":"http:\/\/www.whoocus.com\/blog\/?p=2655"},"modified":"2018-06-01T14:49:34","modified_gmt":"2018-06-01T05:49:34","slug":"phoenix-%e3%81%a7%e3%83%a1%e3%83%bc%e3%83%ab%e3%82%92%e9%80%81%e4%bf%a1%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.blowfish.co.jp\/?p=2655","title":{"rendered":"Phoenix \u3067\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b"},"content":{"rendered":"<p>\u307e\u305a\u306f\u3001\u30e1\u30fc\u30eb\u7528\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f9d\u5b58\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3042\u308b Bumboo \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/p>\n<p>\u25a0 mix.exs<br \/>\n[ruby]<br \/>\n  def application do<br \/>\n    [<br \/>\n      mod: {MyApp.Application, []},<br \/>\n      extra_applications: [:logger, :runtime_tools, :bamboo]<br \/>\n    ]<br \/>\n  end<\/p>\n<p>  defp deps do<br \/>\n    [<br \/>\n      {:phoenix, &quot;~&gt; 1.3.2&quot;},<br \/>\n      {:phoenix_pubsub, &quot;~&gt; 1.0&quot;},<br \/>\n      {:phoenix_ecto, &quot;~&gt; 3.2&quot;},<br \/>\n      {:mariaex, &quot;&gt;= 0.0.0&quot;},<br \/>\n      {:phoenix_html, &quot;~&gt; 2.10&quot;},<br \/>\n      {:phoenix_live_reload, &quot;~&gt; 1.0&quot;, only: :dev},<br \/>\n      {:gettext, &quot;~&gt; 0.11&quot;},<br \/>\n      {:cowboy, &quot;~&gt; 1.0&quot;},<br \/>\n      {:bamboo, &quot;~&gt; 0.7&quot;},<br \/>\n      {:bamboo_smtp, &quot;~&gt; 1.2.1&quot;}<br \/>\n    ]<br \/>\n  end<br \/>\n[\/ruby]<\/p>\n<p>mix deps.get \u3067\u8ffd\u52a0\u3057\u305f\u4f9d\u5b58\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/p>\n<p>[bash]<br \/>\n$ mix deps.get<br \/>\n[\/bash]<\/p>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u3001\u30e1\u30fc\u30eb\u8a2d\u5b9a\u60c5\u5831\u3092\u8ffd\u8a18\u3059\u308b\u3002\u3053\u3053\u3067\u306fSMTP\u30b5\u30fc\u30d0\u3068\u3057\u3066Gmail\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u4f7f\u3046\u3002<\/p>\n<p>\u25a0 config\/config.exs<\/p>\n<p>[ruby]<br \/>\nconfig :myapp, MyApp.Mailer,<br \/>\n       adapter: Bamboo.SMTPAdapter,<br \/>\n       server: &quot;smtp.gmail.com&quot;,<br \/>\n       port: 587,<br \/>\n       username: &quot;my@gmail.com&quot;,<br \/>\n       password: &quot;password&quot;,<br \/>\n       tls: :if_available, # can be `:always` or `:never`<br \/>\n       ssl: false, # can be `true`<br \/>\n       retries: 1<br \/>\n[\/ruby]<\/p>\n<p>\u30e1\u30fc\u30e9\u30fc\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>\u25a0 lib\/myapp\/mailer.ex<\/p>\n<p>[ruby]<br \/>\ndefmodule MyApp.Mailer do<br \/>\n  use Bamboo.Mailer, otp_app: :myapp<br \/>\nend<br \/>\n[\/ruby]<\/p>\n<p>\u30e1\u30fc\u30eb\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>\u25a0 lib\/myapp\/email.ex<\/p>\n<p>[ruby]<br \/>\ndefmodule MyApp.Email do<br \/>\n  use Bamboo.Phoenix, view: MyApp.EmailView<\/p>\n<p>  def hello_email(email) do<br \/>\n    new_email<br \/>\n    |&gt; to(email)<br \/>\n    |&gt; from(&quot;my@gmail.com&quot;)<br \/>\n    |&gt; subject(&quot;Welcome!&quot;)<br \/>\n    |&gt; text_body(&quot;Welcome to My App!!&quot;)<br \/>\n  end<br \/>\nend<br \/>\n[\/ruby]<\/p>\n<p>\u307e\u305a\u306f\u3001\u8a66\u3057\u306b\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u304b\u3089\u30e1\u30fc\u30eb\u3057\u3066\u307f\u308b\u3002<\/p>\n<p>[bash]<br \/>\n$ iex -S mix<br \/>\nInteractive Elixir (1.6.5) &#8211; press Ctrl+C to exit (type h() ENTER for help)<br \/>\niex(1)&gt; MyApp.Email.hello_email(&quot;tajima@whoocus.com&quot;) |&gt; MyApp.Mailer.deliver_now<br \/>\n[debug] Sending email with Bamboo.SMTPAdapter:<\/p>\n<p>%Bamboo.Email{assigns: %{}, bcc: [], cc: [], from: {nil, &quot;my@gmail.com&quot;}, headers: %{}, html_body: nil, private: %{}, subject: &quot;Welcome!&quot;, text_body: &quot;Welcome to My App!!&quot;, to: [nil: &quot;tajima@whoocus.com&quot;]}<\/p>\n<p>%Bamboo.Email{<br \/>\n  assigns: %{},<br \/>\n  bcc: [],<br \/>\n  cc: [],<br \/>\n  from: {nil, &quot;my@gmail.com&quot;},<br \/>\n  headers: %{},<br \/>\n  html_body: nil,<br \/>\n  private: %{},<br \/>\n  subject: &quot;Welcome!&quot;,<br \/>\n  text_body: &quot;Welcome to My App!!&quot;,<br \/>\n  to: [nil: &quot;tajima@whoocus.com&quot;]<br \/>\n}<br \/>\n[\/bash]<\/p>\n<p>\u6b21\u306b\u3001Web\u30a2\u30d7\u30ea\u304b\u3089\u30e1\u30fc\u30eb\u3092\u98db\u3070\u3057\u3066\u307f\u308b\u3002\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u4f5c\u6210\u3057\u3066\u30eb\u30fc\u30bf\u306b\u767b\u9332\u3059\u308b\u3002<br \/>\n\u3053\u3053\u3067\u306f\u3001\u5358\u7d14\u306b\u30da\u30fc\u30b8\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3089\u56fa\u5b9a\u306e\u30e1\u30fc\u30eb\u304c\u98db\u3076\u4ed5\u7d44\u307f\u3002<\/p>\n<p>\u25a0 mail_controller.ex<\/p>\n<p>[ruby]<br \/>\ndefmodule MyApp.MailController do<br \/>\n  use MyApp, :controller<\/p>\n<p>  alias MyApp.Mailer<\/p>\n<p>  def index(conn, _params) do<br \/>\n    MyApp.Email.hello_email(&quot;tajima@whoocus.com&quot;)<br \/>\n      |&gt; Mailer.deliver_now<br \/>\n    render conn, &quot;index.html&quot;<br \/>\n  end<br \/>\nend<br \/>\n[\/ruby]<\/p>\n<p>\u25a0 router.ex<\/p>\n<p>[ruby]<br \/>\n    get &quot;\/mail&quot;, MailController, :index<br \/>\n[\/ruby]<\/p>\n<p>\u3053\u306e\u30da\u30fc\u30b8\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u90fd\u5ea6\u306b\u30e1\u30fc\u30eb\u304c\u98db\u3076\u3002<br \/>\n\u3053\u3053\u3067\u306f\u3001\u500b\u4eba\u7684\u306a\u8a66\u4f5c\u306e\u305f\u3081\u306bGmail\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u306e\u3067\u3001SMTP\u30b5\u30fc\u30d0\u3078\u306e\u30a2\u30af\u30bb\u30b9\u3068\u9001\u4fe1\u306f\u305d\u3053\u305d\u3053\u9045\u3044\u3002<br \/>\n\u30e1\u30fc\u30eb\u30b5\u30fc\u30d0\u3092\u7acb\u3066\u308b\u65b9\u304c\u5b9f\u7528\u7684\u3067\u3042\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u307e\u305a\u306f\u3001\u30e1\u30fc\u30eb\u7528\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u4f9d\u5b58\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3042\u308b Bumboo \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002 \u25a0 mix.exs [ruby] def application do [ mod: {MyApp.Application, [] [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"saved_in_kubio":false,"footnotes":""},"categories":[53,54,4],"tags":[],"class_list":["post-2655","post","type-post","status-publish","format-standard","hentry","category-elixir","category-phoenix-framework","category-tech"],"_links":{"self":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/2655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2655"}],"version-history":[{"count":2,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/2655\/revisions"}],"predecessor-version":[{"id":2949,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=\/wp\/v2\/posts\/2655\/revisions\/2949"}],"wp:attachment":[{"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blowfish.co.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}