Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
recovering from errors in net:smtp
Russell Fulton
10/11/2006 12:57:00 AM
Hi,
I've got a script that sends reports by email using Net::SMTP.
Occassionally I get errors from the mail server (normally rejected
addresses) which causes an exception which I catch with rescue. This is
in a class derived from Net::SMTP:
def send (to, subject, data)
retries = 0
@count += 1
to_array = to.split(/\s*,\s*/)
hdrs = <<HDRS
To: #{to}
Subject: #{subject}
Date: #{Time.now.strftime("%a %b %e %T %Y %z")}
Message-Id: <selms-#{@time}-#{@count}@selms>
From: #{@from}
HDRS
send_message( hdrs + data.join("\n") + ".\n", @from, *to_array)
rescue Net::SMTPFatalError, Net::SMTPSyntaxError
if $! =~ /virtual alias table/ then
retries += 1
STDERR.puts "mail failed #{retries} for #{to}:#{$!}"
spleep(10)
retry if retries <= 2
end
STDERR.puts "mail failed for #{to}:#{$!}"
false
end
I wish to 'reset' the smtp session so that I can continue sending email
without doing a finish and another start (i.e. before I retry). Is this
possible? I've looked through the docs for net::smtp and not found
anything obvious. I have not looked at the source yet.
Russell
--
Posted via
http://www.ruby-...
.
2 Answers
Eric Hodel
10/11/2006 4:48:00 AM
0
On Oct 10, 2006, at 5:56 PM, Russell Fulton wrote:
> I wish to 'reset' the smtp session so that I can continue sending
> email
> without doing a finish and another start (i.e. before I retry). Is
> this
> possible? I've looked through the docs for net::smtp and not found
> anything obvious. I have not looked at the source yet.
I haven't submitted a patch for it yet, but this will do it:
##
# Hack in RSET
class Net::SMTP # :nodoc:
unless instance_methods.include? 'reset' then
##
# Resets the SMTP connection.
def reset
getok 'RSET'
end
end
end
--
Eric Hodel - drbrain@segment7.net -
http://blog.se...
This implementation is HODEL-HASH-9600 compliant
http://trackmap.rob...
Russell Fulton
10/12/2006 9:21:00 PM
0
Eric Hodel wrote:
Thanks very much Eric, I'm sure I could have figured this out for myself
but it would have taken much time and delving into RFCs and source code.
> I haven't submitted a patch for it yet, but this will do it:
Are you going to or should I submit it on your behalf (with appropriate
attribution of course :)
>
> ##
> # Hack in RSET
>
> class Net::SMTP # :nodoc:
>
> unless instance_methods.include? 'reset' then
> ##
> # Resets the SMTP connection.
>
> def reset
> getok 'RSET'
> end
> end
>
> end
>
> --
> Eric Hodel - drbrain@segment7.net -
http://blog.se...
> This implementation is HODEL-HASH-9600 compliant
>
>
http://trackmap.rob...
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
recovering from errors in net:smtp
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password