Quantcast
Channel: 一言多いプログラマーの独り言
Viewing all articles
Browse latest Browse all 846

「Phoenix」フレームワークでBambooを利用してGmailからメール送信

$
0
0
Phoenix」フレームワークでBambooを利用してGmailからメール送信です。GmailをSMTPサーバーとしてメール送信できました。長いトンネルを抜けました。嬉しすぎます(笑)。

/config/config.exs

config :hello_phoenix, HelloPhoenix.Mailer,
adapter: Bamboo.SMTPAdapter,
server: "smtp.gmail.com",
port: 587,
username: "sample_from@gmail.com",
password: "password",
tls: :if_available, # can be `:always` or `:never`
ssl: false, # can be `true`
retries: 1
/lib/hello_phoenix/mailer.ex

defmodule HelloPhoenix.Mailer do
use Bamboo.Mailer, otp_app: :hello_phoenix
end
/lib/email.ex

defmodule HelloPhoenix.Email do
use Bamboo.Phoenix, view: HelloPhoenix.EmailView

def welcome_text_email(email_address) do
new_email
|> to(email_address)
|> from("sample_from@gmail.com")
|> subject("メール送信テスト")
|> text_body("マイクのテスト中\nマイクのテスト中")
end
end

$ iex -S mix
iex(1)> HelloPhoenix.Email.welcome_text_email("sample_to@gmail.com")
|> HelloPhoenix.Mailer.deliver_now

参考サイト
Sending Email(Phoenix)
[Elixir]Send mail from Elixir (Using Mailman Library)(だるい@あぷれんてぃすさん)

Viewing all articles
Browse latest Browse all 846

Trending Articles