「Phoenix」フレームワークでBambooを利用してGmailからメール送信です。GmailをSMTPサーバーとしてメール送信できました。長いトンネルを抜けました。嬉しすぎます(笑)。
/config/config.exs
参考サイト
Sending Email(Phoenix)
[Elixir]Send mail from Elixir (Using Mailman Library)(だるい@あぷれんてぃすさん)
/config/config.exs
/lib/hello_phoenix/mailer.ex
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/email.ex
defmodule HelloPhoenix.Mailer do
use Bamboo.Mailer, otp_app: :hello_phoenix
end
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)(だるい@あぷれんてぃすさん)