我可以使用 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 模板中设置错误?
谢谢