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 :)