我是 ruby on rails mailer 的新手。我Emailer
在mailer
模型中创建。我的代码如下所示。
我的行动邮件Emailer.rb
是:
class Emailer < ActionMailer::Base
default from: 'saghir.alam@xxxxxxx.com'
def contact(recipient, subject, message, sent_at = Time.now)
@subject = subject
@recipients = recipient
@from = 'saghir.alam@xxxxxxx.com'
@sent_on = sent_at
@body= message
@headers = {}
end
end
emailer_controller.rb
class EmailerController < ApplicationController
def sendmail
email = params["emailer"]
recipient = email["recipient"]
subject = email["subject"]
message = email["message"]
Emailer.contact(recipient, subject, message)
return if request.xhr?
render :text => 'Message sent successfully'
end
def index
render :file => 'app\views\emailer\index.rhtml'
end
end
index.rhtml 文件view/emailer
看起来像这样。
<h1>Send Email</h1>
<%= form_for :emailer,:url =>{ :action => :sendmail } do |f| %>
<p><label for="email_subject">Subject</label>
<%= f.text_field 'subject' %></p>
<p><label for="email_recipient">Recipient</label>
<%= f.text_field 'recipient' %></p>
<p><label for="email_message">Message</label>
<%= f.text_area 'message' %></p>
<%= f.submit "Send" %>
<% end %>
这是我的一部分routes.rb
match "/email", to: 'emailer#index'
match "/emailer", to: 'emailer#sendmail'
我config/enivronment/development.rb
是
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.server_settings = {
:address => "smtp.xxxx.com",
:port => 25,
:domain => "xxxx.com",
:authentication => :login,
:user_name => "saghir.alam@xxxxxx.com",
:password => "xxxxxxx",
}
我的问题是当我单击发送按钮时,我可以看到“已发送消息”,如图所示emailer_controller
,但我没有收到任何消息。我的代码有什么问题。请指导我