【发布时间】:2015-07-25 15:31:40
【问题描述】:
我尝试按照教程进行配置,但仍然无法发送电子邮件。在控制台,它显示如下图像:
我在config文件\environments\development.rb和production.rb中配置如下:
config.active_record.dump_schema_after_migration = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: 'gmail username',
password: 'password',
authentication: 'plain',
enable_starttls_auto: true }
app\mailers\user_mailer.rb:
class UserMailer < ApplicationMailer
def registration_confirmation(user)
mail(:to => user.email,:subject => "registered")
end
end
app\mailers\application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: "testonebig@gmail.com"
layout 'mailer'
end
app\controllers\users_controller.rb
def create
@user = User.new(user_params)
UserMailer.registration_confirmation(@user).deliver
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
它运行时显示没有任何错误,但是当我检查 gmail 时,它没有收到任何邮件。
【问题讨论】:
-
如果你使用的是最新的 Rails 版本比如 4.2,你需要将 .deliver 替换为 .deliver_now
-
看起来它仍在使用
delivery_method = :test而不是delivery_method = :smtp- 自从您更改了 development.rb 文件后您是否重新启动了服务器? -
@GauravGupta 当我将其更改为 "UserMailer.registration_confirmation(@user).deliver_now" 并将行添加到配置文件中,如下所示:" :openssl_verify_mode => 'none', :ssl => true, :tls => true}" 它显示 "OpenSSL::SSL::SSLError in UsersController#create"
-
您检查过垃圾邮件文件夹吗?
-
@AmitSharma 它不在垃圾邮件文件夹中
标签: ruby-on-rails