我想使用真实帐户从我的应用程序向 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: 'xuanle.khtn@gmail.com'
def sample_email
mail to: 'leanhxuan_t59@hus.edu.vn', subject: 'Test Mail Rails'
end
end
用户控制器.rb
def index
UserMailer.sample_email.deliver_now
end
生产.rb
config.action_mailer.delivery_method = :smtp
# SMTP settings for gmail
config.action_mailer.smtp_settings = {
:address => "mail.google.com",
:port => 587,
:user_name => 'xuanle.khtn@gmail.com',
:password => '********',
:authentication => "plain",
:enable_starttls_auto => true
}