简体   繁体   English

为什么电子邮件无法在Rails应用程序中发送? 内部服务器错误)第20章。DanielKehoe学习Rails教程

[英]Why are emails not sending in my rails app? Internal Server Error) Ch 20. Learn Rails tutorial by Daniel Kehoe

I am on Ch 20 of the Learn Rails tutorial 'Send Mail'. 我在Learn Rails教程“发送邮件”的第20章中。 There is a create contact form and a notification email is supposed to be sent to my email address. 有一个创建联系表单,并且应该将通知电子邮件发送到我的电子邮件地址。 I have set up configuration as per the book and the email is being generated correctly i the terminal log. 我已经按照书设置了配置,并且在终端日志中正确生成了电子邮件。 however the email never sends to my email inbox. 但是电子邮件永远不会发送到我的电子邮件收件箱。 I am getting an internal server error. 我收到内部服务器错误。 see below for details. 有关详情,请参见下文。

Completed 500 Internal Server Error in 30831ms



Net::OpenTimeout (execution expired):

app/controllers/contacts_controller.rb:10:in `create'

contacts_controller.rb contacts_controller.rb

class ContactsController < ApplicationController

  def new
  @contact = Contact.new
  end

  def create
    @contact = Contact.new(secure_params)
    if @contact.valid?
      UserMailer.contact_email(@contact).deliver_now
      flash[:notice] = "Message sent from #{@contact.name}."
      redirect_to root_path
    else
      render :new
    end
  end

  private
    def secure_params
      params.require(:contact).permit(:name, :email, :content)
    end
end

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

i also have my email address set in the config/secrets.yml file like so : 我也在config / secrets.yml文件中设置了我的电子邮件地址,如下所示:

owner_email: <%= ENV["my_email_address@*******.com"] %>

I have also added the following to my .bashrc file as per the early chater of the book about configuration: 根据有关配置的书的早期内容,我还在.bashrc文件中添加了以下内容:

export SENDGRID_USERNAME="user_name"
export SENDGRID_PASSWORD="password"
export MAILCHIMP_API_KEY="long_random_api_key_here"
export MAILCHIMP_LIST_ID="list_id_here"
export OWNER_EMAIL="**********@*********.com"

so as far as i see i have set everything up according to the tutorial but the mail is not sending. 据我所知,我已经按照教程设置了所有内容,但邮件未发送。 any ideas why? 有什么想法吗?

From the above share code description and log trace, it seems like mailer settings is not configured properly. 从上面的共享代码描述和日志跟踪来看,邮件程序设置似乎配置不正确。

Note: You need to set the mailer settings based on the environment on which you are working(eg: development.rb) 注意:您需要根据工作环境设置邮件程序设置(例如:development.rb)

Follow the below given link for the configuration of mailer settings: 请按照以下给定的链接来配置邮件程序设置:

http://guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration http://guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration

暂无
暂无

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

相关问题 我的cloud9应用程序中的.bashrc文件在哪里? (Daniel Kehoe的学习指南教程) - Where is the .bashrc file in my cloud9 app ? (Daniel Kehoe's learn-rails tutorial book) Windows 上的 .bashrc 文件在哪里? (Daniel Kehoe 的 learn-rails 教程) - Where is the .bashrc file on Windows? (Daniel Kehoe's learn-rails tutorial book) Rails教程ch11 accoun激活。 为什么我的激活电子邮件没有通过sendgrid发送? - Rails tutorial ch11 accoun activation. Why is my activation email not sending with sendgrid? Learn-ruby-on-rails教程,mailchimp不发送任何电子邮件 - learn-ruby-on-rails tutorial, mailchimp not sending any emails Hartl 的 rails 教程 ch11:为什么我的 account_activation 邮件程序模板预览不起作用? - Hartl's rails tutorial ch11: Why is my account_activation mailer template preview not working? Rails教程第2章错误noMethodError:未定义的方法&#39;micropost&#39; - rails tutorial ch 2 error noMethodError: undefined method 'micropost' Hartl的Rails教程ch 11.4生产中的电子邮件:为什么我没有收到电子邮件? + Heroku错误 - Hartl's Rails tutorial ch 11.4 Email in production: why am I not receiving an email? + Heroku error 从Rails教程Ch8 - 为什么不使用实例变量? - From Rails Tutorial Ch8 - why is instance variable not used? 为什么我的rails AJAX请求引发内部服务器错误? - Why does my rails AJAX request throw internal server error? 登录用户(Ruby on Rails教程第8章) - Signing in a User (Ruby on Rails Tutorial Ch. 8)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM