使用 Pony 发送 HAML 电子邮件

发布于 2024-12-03 17:32:31 字数 301 浏览 6 评论 0原文

Sinatra 1.2.6 / Haml 3.1.2 和 Pony

我收到“错误数量的参数错误(0 为 1)”,它指向

我正在发送的sinatra/base.rb

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

:html_body => (haml :html_email) 致 Pony

任何帮助将不胜感激!

M。

Sinatra 1.2.6 / Haml 3.1.2 and Pony

I am getting "wrong number of arguments error (0 for 1)" which points to

sinatra/base.rb

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

I am sending :html_body => (haml :html_email) to Pony

Any help would be very much appreciated!

M.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这个俗人 2024-12-10 17:32:31

您的代码似乎可以在 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 => '[email protected]',
    :from => '[email protected]',
    :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

Your code seems to work in Sinatra 1.2.6, Haml 3.1.3 and Pony 1.3.
Although I would use haml(:test) instead of (haml :test)

test.rb:

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

set :views, Proc.new { root }

get '/send' do
    options = {
    :to => '[email protected]',
    :from => '[email protected]',
    :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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文