使用Pony发送HAML电子邮件

时间:2011-09-08 14:27:41

标签: sinatra haml pony

Sinatra 1.2.6 / Haml 3.1.2和Pony

我得到“错误的参数数量错误(0表示1)”,它指向

屈/ base.rb

def haml(template, options={}, locals={})
  render :haml, template, options, locals
end

我发送:html_body => (haml:html_email)到Pony

非常感谢任何帮助!

微米。

1 个答案:

答案 0 :(得分:1)

您的代码似乎适用于Sinatra 1.2.6,Haml 3.1.3和Pony 1.3。 虽然我会使用haml(:test)代替(haml:test)

test.rb:

require 'rubygems'
require 'sinatra'
require 'pony'
require 'haml'

set :views, Proc.new { root }

get '/send' do
    options = {
    :to => 'user@gmail.com',
    :from => 'user@gmail.com',
    :subject => 'Test',
    :body => 'Test Text',
    :html_body => (haml :test),
    :via => :smtp,
    :via_options => {
      :address => 'smtp.gmail.com',
      :port => 587,
      :enable_starttls_auto => true,
      :user_name => 'login',
      :password => 'password',
      :authentication => :plain,
      :domain => 'HELO'
    }
  }

  Pony.mail(options)
end

test.haml:

!!!
%html
  %head
    %meta{ :content => "text/html; charset=utf-8", :"http-equiv" => "Content-Type" }
    %title Test
  %body
    %h1 Test
    %p Test content