Mass Emailing in Rails

I’ve seen some discussions already in the mailing list about sending
Mass Emails in Rails, but they’ve been pretty unsatisfying.

I’m working with a non-profit with a low budget. They’d like to save
money on email communication by building a tool that will allow them
to send out graphic emails through their site. The hitch is that the
web host has an SMTP throttling limit of 50 recipients/blast and 500
recipients/hour. Their mailing list is just over 500 recipients.

Someone suggested I use a combination of BackgrounDrb and ar_mailer to
feed the emails into a database and cycle through a portion of them
every few minutes. But I’m an intermediate Rails developer and I
couldn’t make heads or tails of some the documentation on those two
tools – especially ar_mailer.

Can anybody provide a better solution or a tutorial/walkthrough on
using BackgrounDrb and ar_mailer together?

P.S. The answer is not to BCC everyone on the mailing list.

Hi,

On 30/05/07, NewMonarch [email protected] wrote:

I’ve seen some discussions already in the mailing list about sending
Mass Emails in Rails, but they’ve been pretty unsatisfying.

I’m working with a non-profit with a low budget. They’d like to save
money on email communication by building a tool that will allow them
to send out graphic emails through their site. The hitch is that the
web host has an SMTP throttling limit of 50 recipients/blast and 500
recipients/hour. Their mailing list is just over 500 recipients.

if you don’t mind to use PHP, there is great free mailing list tool
‘PHPList’.
Interfacing with a Rails application should be easy.

-Thomas

Hi there,

I’ve successfully implemented ar_mailer, and it works well. All emails
get
queued into a database table that looks like this:

create_table :emails do |t|
  t.column :from, :string
  t.column :to, :string
  t.column :last_send_attempt, :integer, :default => 0
  t.column :mail, :text
end

To get your emails going into this table, you subclass your mailer
classes
from ARMailer, like this:

class NotificationMailer < ActionMailer::ARMailer
end

Now, when you tell your rails app to deliver an email, it actually just
gets
queued into that table.

Now you need some sort of background process to check this table
periodically. I handled this by making a little rake task to send out
the
emails from the queue, like this:

desc “Send queued emails”
task :send_queued_emails => :environment do
Dir.chdir(RAILS_ROOT) # change working directory to rails app root so
ar_sendmail will work correctly
ActionMailer::ARSendmail.run([‘-o’])
end

Then I setup a little cron job to run every 15 minutes which runs the
rake
task and send out the emails…

15,30,45,59 * * * * /usr/bin/rake -f /your/rails/app/current/Rakefile
send_queued_emails RAILS_ENV=production >/dev/null 2>&1

Not only that, this domain has all mail sent through GMail servers.
Works
great.


Scott B.
Electro Interactive, Inc.
Office: 813-333-5508
Web: http://electrointeractive.com
Blog: http://sbecker.net

could you give some same of NotificationMailer class?

sorry for typo:
could you give some sample of NotificationMailer class?

class NotificationMailer < ActionMailer::ARMailer
end

Hi,
could you give some same of NotificationMailer class?

bec’z i have sample of email.rb is:

class Email < ActionMailer::ARMailer
def testmail
recipients “[email protected]
from “[email protected]
subject “TEST MAIL SUBJECT”
body “
TEST MAIL MESSAGE”
content_type “text/html”
end
end

and i am sending it through controller like:
mail = Email.create_testmail # => a tmail object
Email.deliver(mail)

but error is occurring:
undefined method `create’ for Email:Class

and when i run ar_sendmail -o, it throw error like:

Unhandled exception undefined method `destroy_all’ for
Email:Class(NoMethodError):

it means it does not consider mail as active record.

please help

Hello Rajesh,

I have exactly the same problem. Did you find a solution to this?

Thanks in advance.

marlor

Rajesh S. wrote:

class NotificationMailer < ActionMailer::ARMailer
end

Hi,
could you give some same of NotificationMailer class?

bec’z i have sample of email.rb is:

class Email < ActionMailer::ARMailer
def testmail
recipients “[email protected]
from “[email protected]
subject “TEST MAIL SUBJECT”
body “
TEST MAIL MESSAGE”
content_type “text/html”
end
end

and i am sending it through controller like:
mail = Email.create_testmail # => a tmail object
Email.deliver(mail)

but error is occurring:
undefined method `create’ for Email:Class

and when i run ar_sendmail -o, it throw error like:

Unhandled exception undefined method `destroy_all’ for
Email:Class(NoMethodError):

it means it does not consider mail as active record.

please help

If you want to save yourself a lot of hassle checkout
http://www.postageapp.com
It’s easy to start and you don’t have to deal with background jobs and
queues plus you have some cool reporting tools - great to track what
actually got sent.

Here’s an introduction:

http://blog.postageapp.com/2009/11/easy-mass-mailing-for-ruby-on-rails/

And here’s a sample app to help get started:

http://blog.postageapp.com/2009/11/rails-example-app/

NewMonarch wrote:

I’ve seen some discussions already in the mailing list about sending
Mass Emails in Rails, but they’ve been pretty unsatisfying.

I’m working with a non-profit with a low budget. They’d like to save
money on email communication by building a tool that will allow them
to send out graphic emails through their site. The hitch is that the
web host has an SMTP throttling limit of 50 recipients/blast and 500
recipients/hour. Their mailing list is just over 500 recipients.

Simplest cheap solution: go through a different SMTP server. I think
Gmail has higher limits.

Someone suggested I use a combination of BackgrounDrb and ar_mailer to
feed the emails into a database and cycle through a portion of them
every few minutes. But I’m an intermediate Rails developer and I
couldn’t make heads or tails of some the documentation on those two
tools – especially ar_mailer.

Well, if you can’t understand your mail sending program, then you’re
screwed. You’ll have to learn to use ActionMailer, ar_mailer, or
whatever.

Can anybody provide a better solution or a tutorial/walkthrough on
using BackgrounDrb and ar_mailer together?

P.S. The answer is not to BCC everyone on the mailing list.

Why not? That’s an eminently sensible solution, and it may be all you
need.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Marnen Laibow-Koser wrote:

NewMonarch wrote:

I’ve seen some discussions already in the mailing list about sending
Mass Emails in Rails, but they’ve been pretty unsatisfying.

I’m working with a non-profit with a low budget. They’d like to save
money on email communication by building a tool that will allow them
to send out graphic emails through their site. The hitch is that the
web host has an SMTP throttling limit of 50 recipients/blast and 500
recipients/hour. Their mailing list is just over 500 recipients.

Simplest cheap solution: go through a different SMTP server. I think
Gmail has higher limits.

Someone suggested I use a combination of BackgrounDrb and ar_mailer to
feed the emails into a database and cycle through a portion of them
every few minutes. But I’m an intermediate Rails developer and I
couldn’t make heads or tails of some the documentation on those two
tools – especially ar_mailer.

Well, if you can’t understand your mail sending program, then you’re
screwed. You’ll have to learn to use ActionMailer, ar_mailer, or
whatever.

That’s it? You’re screwed? No way!!

There’s a tottaly straight forward solution.

1 – Go to postageapp.com and create an account and a project (it’s
FREE). Each project has it’s own API key which will be use to
communicate with PostageApp through the API.

2 – Install the plugin
sudo script/plugin install git://github.com/theworkinggroup/postage.git

The plugin takes care of the communication between your app and
PostageApp integrating seamlessly with ActionMailer. It makes use of the
httparty gem and it will let you know if you need to install it.

3- Create the configuration file by running
rake postage:setup API_KEY=YOUR_API_KEY_HERE

This will create a file in config/initializers/postage.rb with your API
key.

4 – Test the instalation
rake postage:test

This will contact postageapp.com and return some details about your
project and it will attempt to send a test message using your current
configuration. So check your project in PoistageApp and verify that the
test email went through.

5 - Checkout a sample app at:

http://blog.postageapp.com/2009/11/rails-example-app/