[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

smtp.set_debug_output - capture output to string?

uncle

1/30/2008 1:31:00 AM

As shown below, I can send debug output from Net::SMTP to stderr, how
to I send this to a string instead?

smtp = Net::SMTP.new(x[:address], x[:port])
smtp.set_debug_output $stderr
smtp.start(x[:domain], x[:user_name], x[:password],
x[:authentication]) do |smtp|
smtp.sendmail(mail.encoded, mail.from, mail.destinations)
end
4 Answers

uncle

1/30/2008 1:46:00 AM

0

On Jan 29, 7:31 pm, "akt...@gmail.com" <akt...@gmail.com> wrote:
> As shown below, I can send debug output from Net::SMTP to stderr, how
> to I send this to a string instead?
>
> smtp = Net::SMTP.new(x[:address], x[:port])
> smtp.set_debug_output $stderr
> smtp.start(x[:domain], x[:user_name], x[:password],
> x[:authentication]) do |smtp|
> smtp.sendmail(mail.encoded, mail.from, mail.destinations)
> end

fyi, this StringIO technique does not work...

smtp = Net::SMTP.new(x[:address], x[:port])
s = StringIO.new
smtp.set_debug_output s
smtp.start(x[:domain], x[:user_name], x[:password],
x[:authentication]) do |smtp|
smtp.sendmail(mail.encoded, mail.from, mail.destinations)
end
s.rewind
pp s.readlines

Felix Windt

1/30/2008 1:54:00 AM

0

On Wed, 2008-01-30 at 10:34 +0900, aktxyz@gmail.com wrote:
> As shown below, I can send debug output from Net::SMTP to stderr, how
> to I send this to a string instead?
>
> smtp = Net::SMTP.new(x[:address], x[:port])
> smtp.set_debug_output $stderr
> smtp.start(x[:domain], x[:user_name], x[:password],
> x[:authentication]) do |smtp|
> smtp.sendmail(mail.encoded, mail.from, mail.destinations)
> end
>

require 'stringio'
a = StringIO.new
smtp.set_debug_output a

HTH,

Felix


Felix Windt

1/30/2008 2:09:00 AM

0

On Wed, 2008-01-30 at 10:49 +0900, aktxyz@gmail.com wrote:
> On Jan 29, 7:31 pm, "akt...@gmail.com" <akt...@gmail.com> wrote:
> > As shown below, I can send debug output from Net::SMTP to stderr, how
> > to I send this to a string instead?
> >
> > smtp = Net::SMTP.new(x[:address], x[:port])
> > smtp.set_debug_output $stderr
> > smtp.start(x[:domain], x[:user_name], x[:password],
> > x[:authentication]) do |smtp|
> > smtp.sendmail(mail.encoded, mail.from, mail.destinations)
> > end
>
> fyi, this StringIO technique does not work...
>
> smtp = Net::SMTP.new(x[:address], x[:port])
> s = StringIO.new
> smtp.set_debug_output s
> smtp.start(x[:domain], x[:user_name], x[:password],
> x[:authentication]) do |smtp|
> smtp.sendmail(mail.encoded, mail.from, mail.destinations)
> end
> s.rewind
> pp s.readlines
>
>

Works for me:

$ irb
irb(main):001:0> require 'net/smtp'
=> true
irb(main):002:0> require 'stringio'
=> true
irb(main):003:0> a = StringIO.new
=> #<StringIO:0xb7cfa7e4>
irb(main):004:0> s = Net::SMTP.new('zonkalicious.org', 587)
=> #<Net::SMTP zonkalicious.org:587 started=false>
irb(main):005:0> s.set_debug_output a
=> #<StringIO:0xb7cfa7e4>
irb(main):006:0> s.start('nowhere.com', 'nouser', 'nopass')
Errno::ECONNREFUSED: Connection refused - connect(2)
[ ... error trace snipped for brevity ... ]
irb(main):007:0> a.string
=> "opening connection to zonkalicious.org...\n"
irb(main):008:0>


Ignoring the error for a connection refused because I'm using bogus
login data, it does capture debug output to the StringIO object.

HTH,

Felix


uncle

1/30/2008 2:55:00 AM

0

On Jan 29, 8:08 pm, fw <fwmailingli...@gmail.com> wrote:
> On Wed, 2008-01-30 at 10:49 +0900, akt...@gmail.com wrote:
> > On Jan 29, 7:31 pm, "akt...@gmail.com" <akt...@gmail.com> wrote:
> > > As shown below, I can send debug output from Net::SMTP to stderr, how
> > > to I send this to a string instead?
>
> > > smtp = Net::SMTP.new(x[:address], x[:port])
> > > smtp.set_debug_output $stderr
> > > smtp.start(x[:domain], x[:user_name], x[:password],
> > > x[:authentication]) do |smtp|
> > > smtp.sendmail(mail.encoded, mail.from, mail.destinations)
> > > end
>
> > fyi, this StringIO technique does not work...
>
> > smtp = Net::SMTP.new(x[:address], x[:port])
> > s = StringIO.new
> > smtp.set_debug_output s
> > smtp.start(x[:domain], x[:user_name], x[:password],
> > x[:authentication]) do |smtp|
> > smtp.sendmail(mail.encoded, mail.from, mail.destinations)
> > end
> > s.rewind
> > pp s.readlines
>
> Works for me:
>
> $ irb
> irb(main):001:0> require 'net/smtp'
> => true
> irb(main):002:0> require 'stringio'
> => true
> irb(main):003:0> a = StringIO.new
> => #<StringIO:0xb7cfa7e4>
> irb(main):004:0> s = Net::SMTP.new('zonkalicious.org', 587)
> => #<Net::SMTP zonkalicious.org:587 started=false>
> irb(main):005:0> s.set_debug_output a
> => #<StringIO:0xb7cfa7e4>
> irb(main):006:0> s.start('nowhere.com', 'nouser', 'nopass')
> Errno::ECONNREFUSED: Connection refused - connect(2)
> [ ... error trace snipped for brevity ... ]
> irb(main):007:0> a.string
> => "opening connection to zonkalicious.org...\n"
> irb(main):008:0>
>
> Ignoring the error for a connection refused because I'm using bogus
> login data, it does capture debug output to the StringIO object.
>
> HTH,
>
> Felix




Sigh, I had a class that overrides do_start some of Net::SMTP so that
it works with TLS for google, the class had this great line in it...

@socket.debug_output = STDERR #@debug_output

no wonder everything I set was being ignored!

thanks for the help though folks!