【问题标题】:Rails 6: Hostname not known: stmp.gmail.com, SocketErrorRails 6:主机名未知:smtp.gmail.com,SocketError
【发布时间】:2019-11-20 17:45:03
【问题描述】:

我试图向唱歌的人发送欢迎邮件。但我不能这样做...... 我在用户的控制器中添加了 require 'resolv-replace'。有一些错误,但在此行之后已解决。

用户的控制器

 def create
    @user = User.new(set_params)
    if @user.save
      UserNotifierMailer.send_signup_email(@user).deliver
      flash[:success] ="Success"
      redirect_to new_sessions_path
    else
      render 'new'
    end
  end

config/development.rb

Rails.application.configure do
  config.cache_classes = false
  config.eager_load = false
  config.consider_all_requests_local = true
  if Rails.root.join('tmp', 'caching-dev.txt').exist?
    config.action_controller.perform_caching = true
    config.action_controller.enable_fragment_cache_logging = true
    config.cache_store = :memory_store
    config.public_file_server.headers = {
      'Cache-Control' => "public, max-age=#{2.days.to_i}"
    }
  else
    config.action_controller.perform_caching = false
    config.cache_store = :null_store
  end
  config.action_mailer.perform_deliveries = true

  config.active_storage.service = :local

  config.action_mailer.raise_delivery_errors = true

  config.action_mailer.perform_caching = false

  config.active_support.deprecation = :log

  config.active_record.migration_error = :page_load

  config.active_record.verbose_query_logs = true

  config.assets.debug = true

  config.assets.quiet = true

  config.action_mailer.delivery_method = :smtp

  config.file_watcher = ActiveSupport::EventedFileUpdateChecker


  config.action_mailer.smtp_settings = {
    address: "stmp.gmail.com",
    port: 587,
    user_name: "************@gmail.com",
    password: "*******",
    openssl_verify_mode: "none",
    enable_starttls_auto: true,
    authetication: "plain",
  }

  config.action_mailer.default_url_options = { host: "120.0.0.1"  }


end

Application_mailer.rb

class ApplicationMailer < ActionMailer::Base
  default from: '**********@gmail.com' //My gmail username here
  layout 'mailer'
end

错误:SocketError(主机名未知:stmp.gmail.com):

Resolv::ResolvError: stmp.gmail.com 没有地址

【问题讨论】:

  • 您可能希望将地址设置为 smtp.gmail.com 而不是 stmp.gmail.com。
  • 然后显示 Hostname not known: stmp.gmail
  • 在你的开发配置文件中,action mailer SMTP 服务器地址设置为"stmp.gmail.com"。这包含一个错字。它应该是"smtp.gmail.com"

标签: ruby-on-rails rubygems ruby-on-rails-6


【解决方案1】:

有错别字。将stmp.google.com 更改为smtp.google.com。它应该工作!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 2012-11-02
    • 2017-06-08
    相关资源
    最近更新 更多