【发布时间】:2015-03-24 20:53:52
【问题描述】:
我在我的网站上添加了一个联系表格,但遇到了一个问题,当我发送消息时,我收到了我的 Flash 消息,“成功发送”,但是电子邮件从未到达我的收件箱。我目前处于开发模式,我的 app/config 文件看起来像这样
class Application < Rails::Application
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "myemail@gmail.com",
:password => "example",
:authentication => :plain,
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = {
:host => "gmail.com"
}
我的联系人Controller是这样的
def new
@message = Message.new
end
def create
@message = Message.new(params[:message])
if @message.valid?
NotificationsMailer.new_message(@message).deliver
redirect_to(root_path, :notice => "Message was successfully sent.")
else
flash.now.alert = "Please fill all fields."
render :new
end
end
end
最后是我的通知邮件程序
class NotificationsMailer < ActionMailer::Base
default :from => "myemail@gmail.com"
default :to => "myemail@gmail.com"
def new_message(message)
@message = message
if message.file
attachment_name = message.file.original_filename
attachments[attachment_name] = message.file.read
end
mail(:subject => "[myemail@gmail.com] #{message.subject}")
end
end
我是否在这里遗漏了任何明显的东西,因为我已经在另一个运行良好的站点中实现了这个,只是无法弄清楚发生了什么
任何帮助表示赞赏
【问题讨论】:
-
你分析过日志吗?搜索
Sent mail to [RECEIVER'S EMAIL]之类的内容以检查邮件是否发送成功。如果您发现类似的日志,请检查您的垃圾邮件文件夹是否包含邮件? -
我知道这是一个老问题,您可能已经继续前进,但我首先要验证您是否可以使用控制台成功发送电子邮件。在那里实例化并发送电子邮件。
标签: ruby-on-rails-3 actionmailer