ActionMailer outside of Rails to send HTML mails

P

Peter Tellgren

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
 
A

Alex Eiras

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 =3D []
recivers =3D IO.readlines("mial.txt")

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

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

class Emailer < ActionMailer::Base
def test_email(subject, user_email)
subject subject
from "..."
recipients user_email
body :body =3D> @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
=91find_template=92 for []:Array

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

All help welcome


Use ActionMailer::Base.template_root =3D ... 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top