如何在Rails中实际发送电子邮件

问题描述 投票:0回答:1

我想使用真实帐户将电子邮件从我的应用程序发送到Gmail我的代码基于此网站https://guides.rubyonrails.org/action_mailer_basics.html,但是当我运行源代码时,该电子邮件显示在终端上,但确实发送到了我的Gmail帐户。如何将电子邮件发送到我的Gmail帐户,以便可以在https://mail.google.com/mail/u/0/#inbox中查看?

这是我的代码:

user_mailer.rb

class UserMailer < ApplicationMailer
  default from: '[email protected]'

  def sample_email
    mail to: '[email protected]', subject: 'Test Mail Rails'
  end
end

user_controller.rb

def index
    UserMailer.sample_email.deliver_now
end

production.rb

config.action_mailer.delivery_method = :smtp
# SMTP settings for gmail
config.action_mailer.smtp_settings = {
  :address              => "mail.google.com",
  :port                 => 587,
  :user_name            => '[email protected]',
  :password             => '********',
  :authentication       => "plain",
  :enable_starttls_auto => true
}
ruby-on-rails mailer
1个回答
0
投票

将电子邮件功能添加到Rails项目:

© www.soinside.com 2019 - 2024. All rights reserved.