我已经使用了没有rails的actionmailer 2.3,当尝试使用actionmailer4的4.0组件ruby代码时,相同的代码无效。我现在的解决方案有效,我将在答案部分回复。
答案 0 :(得分: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 => "aaaa@xxxx.com",
:password => "ppppp"
}
ActionMailer::Base.view_paths= File.dirname(__FILE__)
class TEST_CLASS_email < ActionMailer::Base
default( {from: "aaaa@xxxx.com"} )
def sendemail(s_email)
@var = 'TESTING VARIABLE PASSING TO VIEW'
mail(
to: "bbbb.cccc@dddd.com",
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("eeee@ffff.com")
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 :)