ar_sendmail 命令不适用于 ruby​​ 1.9.2

发布于 2024-11-14 17:31:10 字数 4678 浏览 3 评论 0原文

我无法从终端运行 ar_sendmail 命令。我不认为我错过了它的配置。下面是我的代码;

development.rb
++++++++++++++++++++++++++++++++++++++++++++++++++++
ActionMailer::Base.delivery_method = :activerecord
ActionMailer::Base.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => 25,
  :domain => "www.google.com",
  :authentication => :plain,
  :user_name => "[email protected]",
  :password => "kathmandu",
  :enable_starttls_auto => true
}
require "action_mailer/ar_mailer"
Gemfile 
+++++++++++++++++++++++++++
gem "ar_mailer", "1.5.1"
My Mailer
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class Postoffice < ActionMailer::ARMailer
  def recover_password_email(account, name, address)
    @recipients = address
    @from = "[email protected]"
    @subject = "Your Account at #{account.org_name} is Ready"
    @body["subdomain"] = account.subdomain
    @body["name"] = name
    @body["org_name"] = account.org_name
    @body["password"] = password
    @body["email"] = address
  end
end
My controller
++++++++++++++++++++++++++++++++++++++++++++++++++++
def reset_password
    @user = User.find_by_email(params[:email])

    begin
      if @user
        password = get_new_password
        @user.update_attributes!(:password => password)
        Postoffice.deliver_recover_password_email(@account, @user.individual.firstname, @user.email, password)
        flash[:notice] = "Your password has been e-mailed to you. It should show up in a minute!"
        redirect_to '/sessions/new'      
      end
    rescue
      flash[:notice] = "Sorry, there was a problem resetting your password."
      redirect_to '/sessions/new'
    end
  end
end

每当我运行 ar_sendmail 命令时,我都会收到以下消息。如果我在控制台中点击 RAILS_ROOT ,那么我会显示 /Users/me/Dev/a5his

Usage: ar_sendmail [options]

ar_sendmail scans the email table for new messages and sends them to the
website's configured SMTP host.

ar_sendmail must be run from a Rails application's root or have it specified
with --chdir.

If ar_sendmail is started with --pid-file, it will fail to start if the PID
file already exists or the contents don't match it's PID.

Sendmail options:
    -b, --batch-size BATCH_SIZE      Maximum number of emails to send per delay
                                     Default: Deliver all available emails
        --delay DELAY                Delay between checks for new mail
                                     in the database
                                     Default: 60
        --max-age MAX_AGE            Maxmimum age for an email. After this
                                     it will be removed from the queue.
                                     Set to 0 to disable queue cleanup.
                                     Default: 604800 seconds
    -o, --once                       Only check for new mail and deliver once
                                     Default: false
    -p, --pid-file [PATH]            File to store the pid in.
                                     Defaults to /var/run/ar_sendmail.pid
                                     when no path is given
    -d, --daemonize                  Run as a daemon process
                                     Default: false
        --mailq                      Display a list of emails waiting to be sent

Setup Options:
        --create-migration           Prints a migration to add an Email table
                                     to stdout
        --create-model               Prints a model for an Email ActiveRecord
                                     object to stdout

Generic Options:
    -c, --chdir PATH                 Use PATH for the application path
                                     Default: .
    -e, --environment RAILS_ENV      Set the RAILS_ENV constant
                                     Default: 
    -t, --table-name TABLE_NAME      Name of table holding emails
                                     Used for both sendmail and
                                     migration creation
                                     Default: Email
    -v, --[no-]verbose               Be verbose
                                     Default: 
    -h, --help                       You're looking at it


ar_sendmail must be run from a Rails application's root to deliver email.

/Users/me/Dev/a5his does not appear to be a Rails application root.

提前致谢 <><

I am not able to run ar_sendmail command from my terminal. I don't think i have missed its configuration. Below is my code;

development.rb
++++++++++++++++++++++++++++++++++++++++++++++++++++
ActionMailer::Base.delivery_method = :activerecord
ActionMailer::Base.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => 25,
  :domain => "www.google.com",
  :authentication => :plain,
  :user_name => "[email protected]",
  :password => "kathmandu",
  :enable_starttls_auto => true
}
require "action_mailer/ar_mailer"
Gemfile 
+++++++++++++++++++++++++++
gem "ar_mailer", "1.5.1"
My Mailer
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class Postoffice < ActionMailer::ARMailer
  def recover_password_email(account, name, address)
    @recipients = address
    @from = "[email protected]"
    @subject = "Your Account at #{account.org_name} is Ready"
    @body["subdomain"] = account.subdomain
    @body["name"] = name
    @body["org_name"] = account.org_name
    @body["password"] = password
    @body["email"] = address
  end
end
My controller
++++++++++++++++++++++++++++++++++++++++++++++++++++
def reset_password
    @user = User.find_by_email(params[:email])

    begin
      if @user
        password = get_new_password
        @user.update_attributes!(:password => password)
        Postoffice.deliver_recover_password_email(@account, @user.individual.firstname, @user.email, password)
        flash[:notice] = "Your password has been e-mailed to you. It should show up in a minute!"
        redirect_to '/sessions/new'      
      end
    rescue
      flash[:notice] = "Sorry, there was a problem resetting your password."
      redirect_to '/sessions/new'
    end
  end
end

Whenever I run ar_sendmail command I just get below message. If i hit RAILS_ROOT in console then I it shows /Users/me/Dev/a5his

Usage: ar_sendmail [options]

ar_sendmail scans the email table for new messages and sends them to the
website's configured SMTP host.

ar_sendmail must be run from a Rails application's root or have it specified
with --chdir.

If ar_sendmail is started with --pid-file, it will fail to start if the PID
file already exists or the contents don't match it's PID.

Sendmail options:
    -b, --batch-size BATCH_SIZE      Maximum number of emails to send per delay
                                     Default: Deliver all available emails
        --delay DELAY                Delay between checks for new mail
                                     in the database
                                     Default: 60
        --max-age MAX_AGE            Maxmimum age for an email. After this
                                     it will be removed from the queue.
                                     Set to 0 to disable queue cleanup.
                                     Default: 604800 seconds
    -o, --once                       Only check for new mail and deliver once
                                     Default: false
    -p, --pid-file [PATH]            File to store the pid in.
                                     Defaults to /var/run/ar_sendmail.pid
                                     when no path is given
    -d, --daemonize                  Run as a daemon process
                                     Default: false
        --mailq                      Display a list of emails waiting to be sent

Setup Options:
        --create-migration           Prints a migration to add an Email table
                                     to stdout
        --create-model               Prints a model for an Email ActiveRecord
                                     object to stdout

Generic Options:
    -c, --chdir PATH                 Use PATH for the application path
                                     Default: .
    -e, --environment RAILS_ENV      Set the RAILS_ENV constant
                                     Default: 
    -t, --table-name TABLE_NAME      Name of table holding emails
                                     Used for both sendmail and
                                     migration creation
                                     Default: Email
    -v, --[no-]verbose               Be verbose
                                     Default: 
    -h, --help                       You're looking at it


ar_sendmail must be run from a Rails application's root to deliver email.

/Users/me/Dev/a5his does not appear to be a Rails application root.

Thanks in advance <><

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

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

发布评论

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

评论(6

泡沫很甜 2024-11-21 17:31:10

使用延迟作业怎么样?我过去使用过 ar mailer,发现延迟工作是更好的解决方案。

https://github.com/collectiveidea/delayed_job

How about using Delayed Job? I've used ar mailer in the past and find delayed job a much better solution.

https://github.com/collectiveidea/delayed_job

爺獨霸怡葒院 2024-11-21 17:31:10

不确定它是否会有所不同,但它说此处

require "action_mailer/ar_mailer"

输入environment.rb,而不是development.rb生产.rb。除此之外,我看不到你错过的任何东西。

Not sure if it'll make a difference, but it says here to put

require "action_mailer/ar_mailer"

in environment.rb, not development.rb or production.rb. Other than that, I can't see anything you missed.

ㄖ落Θ余辉 2024-11-21 17:31:10

尝试 ar_sendmail --chdir /Users/me/Dev/a5his 或在运行命令之前更改为 Rails 应用程序的根目录

Try ar_sendmail --chdir /Users/me/Dev/a5his or changing into the root of your rails app before running the command

誰認得朕 2024-11-21 17:31:10

ar_sendmail 必须从 Rails 应用程序的根目录运行才能发送电子邮件。
/Users/me/Dev/a5his 似乎不是 Rails 应用程序根目录。

您是否在应用程序的根目录中运行该命令?

ar_sendmail must be run from a Rails application's root to deliver email.
/Users/me/Dev/a5his does not appear to be a Rails application root.

Are you running the command in the application's root?

眼前雾蒙蒙 2024-11-21 17:31:10

尝试

cd #{Rails.root.to_s} && bundle exec ar_sendmail_rails3 -e production

try

cd #{Rails.root.to_s} && bundle exec ar_sendmail_rails3 -e production
鹊巢 2024-11-21 17:31:10

如果您查看源代码(如下所示),如果加载配置/环境失败,则会显示此消息。我遇到的一个例子是依赖关系未得到满足,这导致在加载配置/环境时引发异常。要解决此问题,您可以使用 irb 会话并尝试要求配置/环境以查看可能导致要求失败的错误。

Dir.chdir options[:Chdir] do
  begin
    require 'config/environment'
  rescue LoadError
    usage opts, <<-EOF
  #{name} must be run from a Rails application's root to deliver email.
  #{Dir.pwd} does not appear to be a Rails application root.
      EOF
  end
end

If you look at the source (shown below), this message is displayed if loading config/environment fails. One instance of this I ran into was where a dependency was unmet, which was causing an exception to fire when config/environment was being loaded. To address this, you can use an irb session and try requiring config/environment to see what error may be causing the require to fail.

Dir.chdir options[:Chdir] do
  begin
    require 'config/environment'
  rescue LoadError
    usage opts, <<-EOF
  #{name} must be run from a Rails application's root to deliver email.
  #{Dir.pwd} does not appear to be a Rails application root.
      EOF
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文