LoginSignup
39
39

More than 5 years have passed since last update.

RubyでGmailのSMTPサーバを使ってメールを送信する

Posted at

Rubyコード

以下のコードでGmailのSMTPサーバ経由でメールが送信できる。

require 'mail'

mail = Mail.new

options = { :address              => "smtp.gmail.com",
            :port                 => 587,
            :domain               => "smtp.gmail.com",
            :user_name            => '<username>@gmail.com',
            :password             => '<password>',
            :authentication       => :plain,
            :enable_starttls_auto => true  }        
mail.charset = 'utf-8'
mail.from "from@example.com"
mail.to "to@example.com"    
mail.subject "メールタイトル"
mail.body "メール本文"
mail.delivery_method(:smtp, options)
mail.deliver


参考URL

39
39
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
39
39