2013-08-24 2 views
0

이것은 초보자 질문입니다. 실례지만, 레일 작업을 해봤지만 레일을 포함하지 않는 영웅 응용 프로그램에서 보석을 요구하려고 시도한 것은 이번이 처음입니다 - 단지 일반 Ruby 앱. 은 내가 app.rb 파일이처럼 보이는이 확인 : 내가하고 싶은 무엇Actionmailer - heroku app

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 

I는 Gemfile과도의에 actionmailer 포함 한 Gemfile.lock

나는 그것이 경험이 풍부한 루비 dev에 대한 정직하고 뭔가 확신하지만 난 사람이 제발 도움이 될 수 고군분투?

감사

테스트 및 연구의 몇 시간 후
+0

어떤 콘솔에서 실행하나요? app.rb를로드 했습니까? gemfile을 실제로 사용하려면 'bundler/setup'이 필요합니다. –

+0

답장을 보내 주신 Fredrick에게 감사드립니다. 예, app.rb가로드되어 콘솔 (irb가 아님)에서 실행 중이 었습니다. 필요한 사항을 확인하기 위해 수표를 실행했는데 Mail을 사용하여 더 원활하게 작동하는 것으로 나타났습니다. – Jon

답변

0

나는이 실행이 잘 작동 할 때, 나는 그것이 내가이었다 같은 문제가 발생하는 사람을 도움이되기를 바랍니다 내 마지막 코드를했다, 대신 메일을 사용하여 결국 :)

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