【问题标题】:Can not send email by Mailer Rails无法通过 Mailer Rails 发送电子邮件
【发布时间】: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


【解决方案1】:

您是否在 development.rb 文件中提供了正确的电子邮件和密码?

还有一点: 您正在使用此 ID“testonebig@gmail.com”发送电子邮件,请在 gmail 中使用此电子邮件登录。只是为了确保您的帐户一切正常。可能是您的帐户身份验证存在某种问题。

【讨论】:

    猜你喜欢
    • 2011-07-14
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 2020-07-06
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    相关资源
    最近更新 更多