2013-08-24 40 views
0

这是一个新手问题,所以请原谅我,我一直在使用rails,但这是我第一次尝试从heroku应用程序中不包含rails的宝石 - 只是一个普通的Ruby应用程序。 确定我有一个app.rb文件看起来像这样:Actionmailer - heroku应用程序

require "sinatra" 
require 'koala' 
require 'action_mailer' 
ActionMailer::Base.raise_delivery_errors = true 

ActionMailer::Base.delivery_method = :smtp 
ActionMailer::Base.smtp_settings = { 
    :address => "smtp.sendgrid.net", 
    :port  => 587, 
    :domain => "MYDOMAIN", 
    :authentication => :plain, 
    :user_name  => "USER_NAME", 
    :password  => "PASSWORD", 
    :enable_starttls_auto => true 
    } 
ActionMailer::Base.view_paths= File.dirname(__FILE__) 

class TestMailer < ActionMailer::Base 

    default :from => "MY_EMAIL" 

    def welcome_email 
    mail(:to => "MY_EMAIL", :subject => "Test mail", :body => "Test mail body") 
    end 
end 

我想要做的是运行

TestMailer::deliver_test_email 
在控制台

,并得到详细信息或运行

TestMailer::deliver_test_email.deliver 

发送测试邮件

但我得到的是:

NameError: uninitialized constant Object::TestMailer 

我在Gemfile中和它也包含了的ActionMailer Gemfile.lock的

我相信这是一些简单的一个有经验的Ruby开发,但我奋力任何人都可以帮助我吗?

感谢

+0

你是从哪个控制台运行的?你有没有加载app.rb?您还需要为您的gemfile实际使用'bundler/setup'。 –

+0

感谢Fredrick的回应。是的,我加载了app.rb,并且在控制台中运行它(而不是irb)。我运行一些检查来查看需要什么,最后我使用了Mail来代替它,这似乎更加顺利。 – Jon

回答

0

试验和研究的几个小时后,我结束了使用Mail代替,这是我最后的代码在运行时正常工作,我希望它可以帮助谁是有同样的问题,因为我是谁: )

require 'mail' 

Mail.defaults do 

    delivery_method :smtp, { :address => "smtp.sendgrid.net", 

          :port  => 587, 
          :domain => "MY_DOMAIN", 
          :user_name => "USER_NAME", 
          :password => "PASSWORD", 
          :authentication => 'plain', 
          :enable_starttls_auto => true } 
end 

mail = Mail.deliver do 
    to 'EMAIL' 
    from 'Your Name <[email protected]_DOMAIN>' 
    subject 'This is the subject of your email' 
    text_part do 
    body 'hello world in text' 
    end 
    html_part do 
    content_type 'text/html; charset=UTF-8' 
    body '<b>hello world in HTML</b>' 
    end 
end