LoginSignup
4
3

More than 5 years have passed since last update.

GCE + Rails + SendGrid でメール送信

Posted at
  • GCE = Google Compute Engine

SendGridで

Setup guide > SMTP Relay と進んで、API keyを生成します(このキーがパスワードになります)。

Railsで

enviroment.rb または 各環境の設定ファイルにsmtpの設定を追記します。default_url_optionsの設定も忘れずに。ここでコツなのはportに「2525(465や587ではなく)」を指定するところです。ドキュメントにあるとおり、GCEでは主要なメール送信用のポートが閉じられています。

config/enviroments/staging.rb
  config.action_mailer.default_url_options = {
    :host => 'yourdomain.com', :protocol => 'https'}
  ActionMailer::Base.smtp_settings = {
    :user_name => 'apikey',
    :password => 'yourpassword',
    :domain => 'yourdomain.com',
    :address => 'smtp.sendgrid.net',
    :port => 2525,
    :authentication => :plain,
    :enable_starttls_auto => true
  }

参考URL

https://sendgrid.com/docs/Integrate/Frameworks/rubyonrails.html
https://cloud.google.com/compute/docs/tutorials/sending-mail/using-sendgrid

4
3
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
4
3