Gerard has asked for the wisdom of the Perl Monks concerning the following question:

Bit of a silly question really, but this is the first time that I have used Net:SMTP, and I have found that it works well, as far as sending the mail goes, but it seems that something like the following code:
my $smtp = Net::SMTP->new('smtp.orcon.net.nz', Timeout => 30, Debug => 1, ); $smtp->mail('no\@one.com'); $smtp->to(xxx\@yyy.com'); $smtp->data(); $smtp->datasend("To: xxx\@yyy.com\n"); $smtp->datasend("\n"); $smtp->datasend("A simple test message\n"); $smtp->dataend(); $smtp->quit;
Insists on transcribing the SMTP conversation to stdout. That is all very interesting, but all I really want to know is that it worked. I can do this easily enough. I am just wondering if there is an easy way to turn off this printing. ?? Anyone else that has used this before, any suggestions greatly appreciated. Regards, Gerard

Replies are listed 'Best First'.
Re: Net:SMTP Printing to STDOUT
by dws (Chancellor) on Nov 21, 2002 at 22:15 UTC
    Something like the following code ... insists on transcribing the SMTP conversation to stdout.

    Educated guess, but might it have something to do with   Debug => 1 when you're creating the Net::SMTP object?

      Ok, so I'm a little tired. Cheers guys. All sorted. Sometimes sleep deprevation can do strange things to the mind.
(bbfu) (how to tell if send was successful) Re: Net:SMTP Printing to STDOUT
by bbfu (Curate) on Nov 21, 2002 at 22:26 UTC

    According to the docs for Net::SMTP,

    Unless otherwise stated all methods return either a *true* or *false* value, with *true* meaning that the operation was a success. When a method states that it returns a value, failure will be returned as *undef* or an empty list.

    So, you should simply check the return value of $smtp->dataend().

    my $smtp = Net::SMTP->new('smtp.orcon.net.nz', Timeout => 30, Debug => 0, # Prevent debug info to STDO +UT ); $smtp->mail('no@one.com'); # Don't need to escape @ in single-quotes $smtp->to('xxx@yyy.com'); # Fixed typo; you forgot opening quote. :) $smtp->data(); $smtp->datasend("To: xxx\@yyy.com\n"); $smtp->datasend("\n"); $smtp->datasend("A simple test message\n"); my $res = $smtp->dataend(); $smtp->quit; print "Operation was ", $res ? '' : 'un', "successful.\n";

    Also, you might want to just pass the message to $smtp->data(), as it looks cleaner (personal opinion :)

    use Net::SMTP; my $smtp = Net::SMTP->new('smtp.example.com', Timeout => 30, Debug => 0, # Prevent debug info to STDO +UT ); $smtp->mail('someone@example.com'); $smtp->to('someone@example.com'); my $ret = $smtp->data(<<'EOM'); From: someone@example.com To: someone@example.com Subject: Test Message A simple test message. EOM print "Operation was ", $ret ? '' : 'un', "successfull.\n"; print "(Got response: ", $smtp->message(), ")\n"; $smtp->quit;

    bbfu
    Black flowers blossum
    Fearless on my breath