我正在配置在用户使用设备注册后发送的电子邮件确认。我做了所说的所有事情(https://github.com/plataformatec/devise/wiki/How-To:-Add-:confirmable-to-Users),但它仍然不起作用。
以下是一些代码:
//development.rb
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
//devise.rb
config.mailer_sender = 'myEmail@gmail.com'
# Configure the class responsible to send e-mails.
config.mailer = "Mailer"
//Mailer.rb
class Mailer < Devise::Mailer
helper :application
include Devise::Controllers::UrlHelpers
default template_path: 'devise/mailer'
end
我是否需要配置更多内容才能在开发环境中发送电子邮件确认函?
答案 0 :(得分:2)
是的,您必须为要发送的电子邮件配置smtp设置,如:
require 'tlsmail'
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
ActionMailer::Base.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default :charset => "utf-8"
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "YOUR_EMAIL",
:password => 'PASSWORD',
:authentication => "plain",
:enable_starttls_auto => true
}
将以上代码添加到development.rb
以配置smtp
设置。请在需要的代码中添加您的电子邮件和密码。
希望它能正常工作!
答案 1 :(得分:1)
除了@ Muhammad的回答,还要在 development.rb
中加入以下代码行config.action_mailer.default_url_options = {host: 'your server' } # ex. localhost:3000
config.action_mailer.raise_delivery_errors = true # to raise error if smtp has error on setup
config.action_mailer.default :charset => "utf-8"
答案 2 :(得分:0)
在initializers / devise.rb中 config.mailer_sender ='您的电子邮件'
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 465,
domain: 'gmail.com',
user_name: 'your email',
password: 'your password',
authentication: 'plain',
enable_starttls_auto: true,
ssl: true
}