【问题标题】:How to send mail with Sinatra using Pony?如何使用 Pony 通过 Sinatra 发送邮件?
【发布时间】:2015-11-06 01:10:42
【问题描述】:

我在使用我在 Sinatra 中构建的联系表单发送电子邮件时遇到问题。我正在使用小马宝石。出于某种原因,我收到此错误消息“不存在此类文件-哪个 sendmail”。我已经安装了“sendmail”,但我仍然遇到同样的问题。我愿意接受任何建议。代码如下:

联系表格

<form action='/' id='contact' name='contact' method='post' novalidate='novalidate' >

                    <div class="form-group">

                        <div class="input-wrap">
                        <input type="text" class='form-control' name='name' id='name' placeholder='NAME'>
                        </div>

                        <br>

                    <div class="input-wrap">
                        <input type="email" class='form-control' name='mail' id='mail' placeholder='EMAIL'>
                    </div>

                    <br>

                    <div class="input-wrap">
                        <input type="text" class='form-control' name='subject' id='subject' placeholder='SUBJECT'>

                    </div>

                    <br>
                    <div class="input-wrap">
                        <textarea placeholder='MESSAGE' class='form-control' name="body" id="body" cols="30" rows="10"></textarea>
                    </div>
                    <br>

                    <input type='submit' value='SEND' id='button'>
                    </div>
                </form>

main.rb

require 'rubygems'
require 'sinatra'
require 'bundler/setup'



get '/' do 
File.read('index.html')
end

post '/' do
require 'pony'
name  = params[:name]
mail = params[:mail]
subject = params[:subject]
body  = params[:body]


Pony.mail(:to => 'mjstokes1986@att.net', :from => '#{name}', :subject => '#{subject}', :body => '#{body}')

# File.read('index.html')

redirect '/success'

end

get '/success' do
File.read('success.html')
end

【问题讨论】:

  • 复制并粘贴完整的错误消息。 $ which sendmail 的输出是什么?
  • Errno::ENOENT at / No such file or directory - which sendmail

标签: ruby forms email sinatra pony


【解决方案1】:

尝试告诉Pony.mail 方法在哪里可以找到您的sendmail。您可以使用 which sendmail 找到您的 sendmail 位置。 (如果这没有返回任何内容,那么您只是没有正确安装 sendmail)。

Pony.mail({
  ...
  :via_options => { :location  => '/path/to/your/sendmail'}
})

【讨论】:

  • 我已经下载并安装了 sendmail。如何找到路径?
  • 在您的 shell 中输入 which sendmail(如果您使用的是 Mac 或 Linux)。它应该返回类似/usr/sbin/sendmail 的内容。如果它没有返回任何内容,则说明安装存在一些问题。
  • 这就是我的设置Pony.mail({ :to =&gt; 'mjstokes1986@att.net', :from =&gt; '#{name}', :subject =&gt; '#{subject}', :body =&gt; '#{body}', :via_options =&gt; {:location =&gt; '/c/sendmail/./sendmail'} })
  • /c/sendmail/./sendmailwhich sendmail的结果吗,路径看起来很奇怪?
  • 我输入which sendmail时返回的内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多