奇怪的行为小马邮件Sinatra

时间:2013-07-02 08:59:05

标签: ruby email sinatra mailer pony

我可以使用Sinatra和Pony邮件从我的网站发送邮件。问题在于设置正文以使用erb模板。

所以我的配置设置如此

post '/' do
from = params[:name]
subject = "#{params[:name]} has contacted you"
body = erb(:mail)

Pony.mail(
:from => from,
:to => ENV["EMAIL_ADDRESS"],
:subject => subject,
:body => body,
:via => :smtp,
:via_options => {
:address              => 'smtp.gmail.com',
:port                 => '587',
:enable_starttls_auto => true,
:user_name            => ENV["USER_NAME"],
:password             => ENV["PASSWORD"],
:authentication       => :plain, 
:domain               => "localhost.localdomain" 
 })

flash[:notice] = "Thanks for your email. I will be in touch soon."
redirect '/success' 

所以我的主题呈现了相关性,但邮件的正文实际上是作为我的网页的html源返回的(就好像我有右键单击的查看源)

我的erb模板就像这样

Hello Rich,

Seems as if you have recieved an email from <%= params[:name] %> via your website.

Their email address is <%= params[:email] %>, this is what they said.

<%= params[:message] %>

那么为什么身体不会呈现erb tempalte?

我在这里有点困惑?我在erb模板中设置错误吗?

由于

1 个答案:

答案 0 :(得分:1)

好的,对于其他有同样问题的人我需要做的是告诉sinatra不要使用我的布局文件,所以在设置时

body = erb(:mail)

需要

body = erb(:mail, layout: false )