[英]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.