简体   繁体   English

在Learn-Rails教程中出现错误“发送消息需要SMTP到地址”

[英]Error “An SMTP To address is required to send a message” on Learn-Rails Tutorial

I keep getting error on "Send Mail" section on the Learn Ruby on Rails tutorial. 我一直在学习Ruby on Rails教程的“发送邮件”部分得到错误。

I have tried to clone https://github.com/RailsApps/learn-rails.git on my local machine but the issue is still here. 我试图在我的本地计算机上克隆https://github.com/RailsApps/learn-rails.git但问题仍然存在。

Below is my code: 以下是我的代码:

user_mailer.rb user_mailer.rb

class UserMailer < ApplicationMailer
  default from: "do-not-reply@example.com"

  def contact_email(contact)
    @contact = contact
    mail(to: Rails.application.secrets.owner_email, from: @contact.email, :subject => "Website Contact")
  end
end

development.rb development.rb

config.action_mailer.smtp_settings = {
    address: "smtp.gmail.com",
    port: 587,
    domain: Rails.application.secrets.domain_name,
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: Rails.application.secrets.email_provider_username,
    password: Rails.application.secrets.email_provider_password
  }
  # ActionMailer Config
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true
  # Send email in development mode?
  config.action_mailer.perform_deliveries = true

secrets.yml secrets.yml

development:
  email_provider_username: <%= ENV["GMAIL_USERNAME"] %>
  email_provider_password: <%= ENV["GMAIL_PASSWORD"] %>
  mailchimp_api_key: <%= ENV["MAILCHIMP_API_KEY"] %>
  mailchimp_list_id: <%= ENV["MAILCHIMP_LIST_ID"] %>
  domain_name: example.com
  owner_email: <%= ENV["OWNER_EMAIL"] %>

I have also made sure that the environment variables were set up correctly on .bashrc file. 我还确保在.bashrc文件中正确设置了环境变量。

Any help will be greatly appreciated, and thank you in advance! 任何帮助将不胜感激,并提前感谢您!

For development, you can use the letter opener gem. 对于开发,您可以使用开信刀宝石。 Once you send an email it'll automatically open in your default browser. 发送电子邮件后,它将自动在默认浏览器中打开。

Add the following to the development section of your Gemfile. 将以下内容添加到Gemfile的开发部分。

gem 'letter_opener'

I too was having the identical issue. 我也有同样的问题。 I tried everything from disabling 2-step verification (Google) to hardcoding my credentials in the secrets.yml with zero success. 我尝试了从禁用两步验证(Google)到在secrets.yml中硬编码我的凭据,但没有成功。

I used my outlook.com credentials and it worked perfectly. 我使用了我的outlook.com凭据,它运行得很好。

Note: this requires a change in development.rb 注意:这需要更改development.rb

config.action_mailer.smtp_settings = {       
    address : "smtp.live.com"
    # everything else is identical.
}

Setting it for gmail 为gmail设置它

ActionMailer::Base.delivery_method = :smtp
    ActionMailer::Base.smtp_settings = {
      :address => "smtp.gmail.com",
      :domain => "gmail.com",
      :port => 587, 
      :user_name => "username",
      :password => "password",
      :authentication => :plain,
      :enable_starttls_auto => true,
      :openssl_verify_mode => 'none' 
    }

make it true config.action_mailer.raise_delivery_errors = true it will tell if any error occurs. make it true config.action_mailer.raise_delivery_errors = true它会告诉是否发生任何错误。

Also try port 25 也尝试端口25

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ArgumentError(发送消息需要SMTP To地址-Rails 4 - ArgumentError (An SMTP To address is required to send a message - Rails 4 发送消息需要SMTP地址 - An SMTP to address is required to send a message 我正在关注http://learn-rails.com/上的Learn-rails教程书2 - I'm following the learn-rails tutorial book 2 from http://learn-rails.com/ SMTP To地址是发送消息/参数错误所必需的 - An SMTP To address is required to send a message/Argument Errror learning-rails捆绑包安装错误,解析Gemfile - learn-rails bundle install error parsing Gemfile 我的cloud9应用程序中的.bashrc文件在哪里? (Daniel Kehoe的学习指南教程) - Where is the .bashrc file in my cloud9 app ? (Daniel Kehoe's learn-rails tutorial book) 在google_drive gem / learn-rails教程创建的GoogleDrive上找不到电子表格 - cant find spreadsheet on GoogleDrive which was created by google_drive gem / learn-rails tutorial Windows 上的 .bashrc 文件在哪里? (Daniel Kehoe 的 learn-rails 教程) - Where is the .bashrc file on Windows? (Daniel Kehoe's learn-rails tutorial book) SMTP To地址是发送消息所必需的。 将消息smtp_envelope_to设置为,抄送或密送地址 - An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address ArgumentError:发送消息需要SMTP To地址。 设置消息smtp_envelope_to,to,cc或bcc地址 - ArgumentError: An SMTP To address is required to send a message. Set the message smtp_envelope_to, to , cc, or bcc address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM