繁体   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

我在Learn Rails教程“发送邮件”的第20章中。 有一个创建联系表单,并且应该将通知电子邮件发送到我的电子邮件地址。 我已经按照书设置了配置,并且在终端日志中正确生成了电子邮件。 但是电子邮件永远不会发送到我的电子邮件收件箱。 我收到内部服务器错误。 有关详情,请参见下文。

Completed 500 Internal Server Error in 30831ms



Net::OpenTimeout (execution expired):

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

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

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

我也在config / secrets.yml文件中设置了我的电子邮件地址,如下所示:

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

根据有关配置的书的早期内容,我还在.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"

据我所知,我已经按照教程设置了所有内容,但邮件未发送。 有什么想法吗?

从上面的共享代码描述和日志跟踪来看,邮件程序设置似乎配置不正确。

注意:您需要根据工作环境设置邮件程序设置(例如:development.rb)

请按照以下给定的链接来配置邮件程序设置:

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM