Forum: Ruby on Rails Multiple emails from one SMTP connection?

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.
E37ca8b3eee534fa6781f7ba13743afb?d=identicon&s=25 Ryan Wood (Guest)
on 2006-01-04 18:12
(Received via mailing list)
Hi all. I'm running a nightly job that is creating a CSV file and
sending to member via SMTP. I got the following error after about 20
emails or so: Net::SMTPServerBusy Too many connections from IP...

Is there a way (using ActionMailer) to open a connection and send
multiple emails. Or could I make sure the connection is closed before
opening another? The only other option is to send some type of wait
signal if I catch that error. Any other ideas?


Thanks for the help!

--Ryan
5ceea097a3b29cb6a5da6705926410f4?d=identicon&s=25 Gerret Apelt (Guest)
on 2006-01-04 18:14
(Received via mailing list)
Ryan,

if you're not customizing the email on a per-recipient basis,
definitely go for sending you email in a single SMTP session. I
believe the ActionMailer API doesn't let you do that as-is.
ActionMailer uses the TMail library internally though, so you might be
able to intercept the TMail instance generated by ActionMailer, and
then send it to multiple recipients, taking away the SMTP portion of
the work from ActionMailer and doing it yourself.

In pseudo-brief, somewhat like this

Net::SMTP.start(server, port) do |sender|
  recipients.each do |recipient|
    tmail.to = recipient
    sender.sendmail tmail.encoded, tmail.from, [recipient]
  end
end

Exactly where to intercept the Tmail object created by ActionMailer,
you'd have to dig to find out.

cheers
Gerret
37b7b848b1e3d667174d28d32d04bcee?d=identicon&s=25 Charles M. Gerungan (Guest)
on 2006-01-04 22:34
(Received via mailing list)
On 4-jan-2006, at 17:04, Ryan Wood wrote:

> Is there a way (using ActionMailer) to open a connection and send
> multiple emails. Or could I make sure the connection is closed before
> opening another? The only other option is to send some type of wait
> signal if I catch that error. Any other ideas?

Talk directly to sendmail (or qmail-inject, or whatever)?

--
Regards, Charles.
337cdd270761e0e6f4356de45b04d388?d=identicon&s=25 Jonathan Viney (Guest)
on 2006-01-05 13:00
I wanted to do the same thing and have written a patch,
http://dev.rubyonrails.org/ticket/3307. It allows you to pass an array
of messages to ActionMailer::Base.deliver which will all be delivered
with one SMTP connection. It works ok for me, apart from the error
handling (see ticket).

You'd use it like...

emails = []
emails << MyMailer.create_message
emails << MyMailer.create_message

MyMailer.deliver(emails)

Cheers,
Jonathan

Ryan Wood wrote:
> Hi all. I'm running a nightly job that is creating a CSV file and
> sending to member via SMTP. I got the following error after about 20
> emails or so: Net::SMTPServerBusy Too many connections from IP...
>
> Is there a way (using ActionMailer) to open a connection and send
> multiple emails. Or could I make sure the connection is closed before
> opening another? The only other option is to send some type of wait
> signal if I catch that error. Any other ideas?
>
>
> Thanks for the help!
>
> --Ryan
E37ca8b3eee534fa6781f7ba13743afb?d=identicon&s=25 Ryan Wood (Guest)
on 2006-01-05 20:09
(Received via mailing list)
Thanks a lot. I'll give that a shot. In the meantime, I have my host
adjust their spam controls to allow more connections which has been
temporary fix.

--Ryan
This topic is locked and can not be replied to.