gpt4 book ai didi

ruby-on-rails - Learn-Rails 教程错误 "An SMTP To address is required to send a message"

转载 作者:行者123 更新时间:2023-12-02 04:47:17 26 4
gpt4 key购买 nike

我在 Learn Ruby on Rails 上的“发送邮件”部分不断收到错误消息教程。

我试过克隆https://github.com/RailsApps/learn-rails.git在我的本地机器上,但问题仍然存在。

下面是我的代码:

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

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

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"] %>

我还确保在 .bashrc 文件上正确设置了环境变量。

任何帮助将不胜感激,在此先感谢您!

最佳答案

对于开发,您可以使用 letter opener gem。发送电子邮件后,它会在您的默认浏览器中自动打开。

将以下内容添加到 Gemfile 的开发部分。

gem 'letter_opener'

关于ruby-on-rails - Learn-Rails 教程错误 "An SMTP To address is required to send a message",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31888911/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com