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