2015-05-04 3 views
0

Я использовал actionmailer 2.3 без рельсов, и при попытке использовать тот же код с компонентом rubyl кода 4.0, который использует actionmailer4, не работает. У меня есть решение, которое работает, и я собираюсь ответить в разделе ответов.Как использовать Actionmailer4 без рельсов

ответ

0
require 'rubygems' 
    require 'action_mailer' 

    ActionMailer::Base.delivery_method = :smtp 
    ActionMailer::Base.smtp_settings = { 
     :enable_starttls_auto => :true, 
     :address => "smtp.gmail.com", 
     :port => 587, 
     :domain => "xxxx.com", 
     :authentication => :plain, 
     :user_name => "[email protected]", 
     :password => "ppppp" 
    } 

    ActionMailer::Base.view_paths= File.dirname(__FILE__) 

    class TEST_CLASS_email < ActionMailer::Base 
     default({from: "[email protected]"}) 

     def sendemail(s_email) 
     @var = 'TESTING VARIABLE PASSING TO VIEW' 
     mail(
      to: "[email protected]", 
      subject: "Testing out from ACTIONMAILER4", 
      bcc: s_email 
     ) 
     end 
    end 

    def testemailpubmethod(email) 
     begin 
     e=TEST_CLASS_email.sendemail(email) 
     if e.present? 
     e.deliver_now 
     end 
     rescue Exception => exception 
     puts "Email:Exception Message: #{exception.message}" 
     puts "Error sending the email #{exception.backtrace.join("\n")}" 
     end 
    end 

    testemailpubmethod("[email protected]")  


Now create the template files in the following subdirectory. 
============================================================ 
./test_class_email/sendemail.text.erb 
===================================== 
    This is a text email from <%= @var %> 
    -Have fun using Actionmailer4 :)