簡體   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