我创建了简单的联系表单,我的网站访问者可以使用ActionMailer直接从该表单向我们发送一些问题。
我做了本指南中的所有内容: http://guides.rubyonrails.org/action_mailer_basics.html
我的邮件代码:
class Mailer < ActionMailer::Base
default from: 'notifications@example.com'
def welcome_email(mail)
@mail = mail
mail(to: @mail.email, subject: 'Welcome to My Awesome Site')
end
end
梅勒观点:
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Welcome to example.com, <%= @mail.name %></h1>
<p>
You have successfully signed up to example.com,
your username is: <br/>
</p>
<p>
To login to the site, just follow this link:
</p>
<p>Thanks for joining and have a great day!</p>
</body>
</html>
然后我创建了控制器邮件,创建邮件时会自动发送该邮件。
我的创作动作:
def create
@mail = Mail.new(params[:mail])
respond_to do |format|
if @mail.save
# Tell the UserMailer to send a welcome Email after save
Mailer.welcome_email(@mail).deliver
format.html { redirect_to(@mail, notice: 'User was successfully created.') }
format.json { render json: @mail, status: :created, location: @mail }
else
format.html { render action: 'new' }
format.json { render json: @mail.errors, status: :unprocessable_entity }
end
end
我的日志文件:
Sent mail to ekk (2128ms)
Date: Fri, 24 Jan 2014 10:29:49 +0200
From: notifications@example.com
To: ekk
Message-ID: <52e2247dd72a4_1c50126a9b047573@Edzuks-PC.mail>
Subject: Welcome to My Awesome Site
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Completed 500 Internal Server Error in 2321ms
Errno::ECONNREFUSED (No connection could be made because the target machine actively refused it. - connect(2)):
app/controllers/messages_controller.rb:31:in `block in create'
app/controllers/messages_controller.rb:29:in `create'
Rendered c:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered c:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
Rendered c:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (21.0ms)
问题
我设置了所有smtp设置,在日志文件中我可以看到该消息已创建但仍然出现此错误:
Errno::ECONNREFUSED (No connection could be made because the target machine actively refused it. - connect(2)):
我尝试将该电子邮件地址更改为实际地址,但没有成功。 有人可以向我提示吗?
谢谢!