Jae*_*ger 2 gmail actionmailer ruby-on-rails-4
我已经查看了此问题的先前答案,但我仍然无法弄清楚我的参数有什么问题。
我修改了我的 Gmail 帐户,使其允许安全性较低的应用程序,并使用验证码解锁它,但它仍然不接受我的用户名和密码,即使我确信它们是正确的。
这是我的文件:
配置/环境/生产.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "mymail@gmail.com",
:password => "mypassword",
:authentication => :login,
:enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)
配置/初始化程序/smtp_settings.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mywebsite.fr",
:user_name => "myemail@gmail.com",
:password => 'myPassword',
:authentication => :login,
:enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)
我想我做错了什么,或者把东西放在不属于的地方。在看到了这么多不同的方法后,我迷失了。
小智 5
我是一名初学者,这是我第一次在 stackoverflow 上发帖,希望这对您有所帮助。如果我可以进一步帮助您,请告诉我!另外,如果您想使用 sendgrid 和 heroku,我也可以提供帮助。
因此,当涉及到我的 Gmail 身份验证设置时,我还必须允许安全性较低的应用程序,并解锁验证码。除了 Gmail 设置中的这两项更改之外,我还必须转到我的 Gmail 设置 > 转发和 POP/IMAP>,然后单击启用 IMAP。保存您的更改。这些都是我对我的 Gmail 所做的所有更改。
进行以下更改:
config/initializers/setup_mail.rb 将身份验证更改为 :plain
if Rails.env.development? || Rails.env.production?
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: 'smtp.gmail.com',
port: '587',
authentication: :plain,
user_name: 'yourEmail@gmail.com',
password: 'yourSecureGmailPassword',
domain: 'mail.google.com',
enable_starttls_auto: true
}
end
Run Code Online (Sandbox Code Playgroud)
config/environments/test.rb 主机是一个网站,因为我使用的是cloud9
config.action_mailer.default_url_options = { host: 'https://blocipedia-sunnygoo.c9users.io', port: 3000 }
Run Code Online (Sandbox Code Playgroud)
配置/环境/development.rb
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: 'same as in test.rb', port: 3000 }
Run Code Online (Sandbox Code Playgroud)
应用程序/模型/user.rb
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
Run Code Online (Sandbox Code Playgroud)
应用程序/邮件程序/application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout 'mailer'
end
Run Code Online (Sandbox Code Playgroud)
应用程序/邮件程序/user_mailer.rb
class UserMailer < ApplicationMailer
default from: "sunnydgoswami@@gmail.com"
def new_user(user)
@user = user
mail(to: user.email, subject: "Welcome to Blocipedia!")
end
end
Run Code Online (Sandbox Code Playgroud)
应用程序/视图/布局/mailer.html.erb
<html>
<body>
<%= yield %>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
应用程序/视图/布局/mailer.text.erb
<%= yield %>
Run Code Online (Sandbox Code Playgroud)
应用程序/视图/user_mailer/new_user.html.erb
'<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-
equiv="Content-Type" />
</head>
<body>
<h1>Welcome, new user!</h1>
<p>
<%= @user.email %>, join us in creating a vibrant wiki
atmosphere!
</p>
<p>
You signed up using <%= @user.email %>. You will be
using this email next time to log in.
</p>
</body>
</html>'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2681 次 |
| 最近记录: |