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
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 On 1/4/06, Ryan Wood <ryan.wood@gmail.com> 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Charles M. Gerungan
2006-Jan-04 21:33 UTC
[Rails] Multiple emails from one SMTP connection?
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.
Jonathan Viney
2006-Jan-05 12:00 UTC
[Rails] Re: Multiple emails from one SMTP connection?
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-- Posted via http://www.ruby-forum.com/.
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 On 1/5/06, Jonathan Viney <jviney@spreydon.org.nz> wrote:> 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 > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >