Forum: Ruby ActionMailer outside of Rails to send HTML mails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ca3157741cbddceb2febac45bda6f511?d=identicon&s=25 Peter Tellgren (petertellgren)
on 2009-04-23 11:47
I am trying to build a small newsletter application.
I am however failing somehomw..

I am trying this simple sample code:

<pre>
require 'net/http'
require 'rubygems'
require 'action_mailer'

recivers = []
recivers = IO.readlines("mial.txt")

h = Net::HTTP.new('http://...', 80)
resp, @data = h.get('...', nil)

ActionMailer::Base.default_content_type = "text/html"
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address  => "...",
  :port  => 25,
  :domain  => '...'
}

class Emailer < ActionMailer::Base
  def test_email(subject, user_email)
    subject    subject
    from       "..."
    recipients user_email
    body       :body => @data
  end
end

recivers.each do |reciver|
        Emailer.deliver_test_email("Testing", reciver)
end
</pre>

And when I run this I get NoMethodError: undefined method
‘find_template’ for []:Array

I suppose I have to have a template somewhere but I can't figure out
where to put it?

All help welcome
72c015d3601e275d5ee8a214e89cf03a?d=identicon&s=25 Alex Eiras (Guest)
on 2009-04-23 13:01
(Received via mailing list)
> recivers = []
>  :domain  => '...'
>
>
> All help welcome


Use ActionMailer::Base.template_root = ... to set the path your email
templates reside in. In your example, ActionMailer will search for a
template named 'test_email' (plus extension) unless you provide a
different
one to render_message method.

Hope it helps
Cheers

Alex
This topic is locked and can not be replied to.