ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => ???,
:user_name => ???,
:password => ???,
:authentication => "plain",
:enable_starttls_auto => true
}
我正在尝试使用 Action Mailer在 Rails 中向用户发送电子邮件。我不太明白 :domain
、:user_name
和 :password
应该包含什么内容。应该是 gmail.com
、我的 Gmail 用户名和 Gmail 密码吗?
最佳答案
以下是设置 ActionMailer 以使用 GMAil 发送邮件的示例:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa9783a58f899f88a5949b979fba9d979b9396d4999597" rel="noreferrer noopener nofollow">[email protected]</a>',
:password => 'my_gmail_password',
:authentication => 'plain',
:enable_start_tts_auto => true
}
域名应为“gmail.com”,用户名和密码应为您的 Google 帐户的用户名和密码。为了更好地保护您的主 GMail 帐户,您应该设置一个单独的 GMail 帐户仅用于发送电子邮件。
关于ruby-on-rails - ActionMailer 中的 :domain, :user_name, 和 :password,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12984447/