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

I'm using the following code to try and forward my mail from a pop account to my gmail using my ISP's SMTP server. Unfortunately, it never seems to work quite right. In the log file I get something like:
... Net::SMTP=GLOB(0x16e2b34)>>> right" Net::SMTP=GLOB(0x16e2b34)>>> >r</span><BR> Net::SMTP=GLOB(0x16e2b34)>>> </DIV></BODY></HTML> Net::SMTP=GLOB(0x16e2b34)>>> ------=_NextPart_000_0001_01C65387.769711 +20-- Net::SMTP=GLOB(0x16e2b34)>>> . Net::SMTP: Unexpected EOF on command channel at C:\perl\forwarder.pl l +ine 29
Any ideas?
#!perl use Net::POP3; use Net::SMTP; my $ServerName = "pop.server"; my $pop3 = Net::POP3->new($ServerName, Debug => 0); #redirect err open STDERR, ">>C:\\mail.log"; my $UserName = "username"; my $Password = "password"; my $msg_id; my $smtp = Net::SMTP->new('smtp.server', Debug => 1); die "Couldn't log on to server" unless $pop3; my $Num_Messages = $pop3->login($UserName, $Password); my $Messages = $pop3->list(); for $msg_id (keys(%$Messages)) { my $MsgContent = $pop3->get($msg_id); $smtp->mail('from@me.com'); $smtp->to('forward@address.com'); $smtp->data(); for (@$MsgContent) { $smtp->datasend($_); } $smtp->dataend(); my $delete_msg = $pop3->delete($msg_id); close OUT; } $smtp->quit(); $pop3->quit();

Replies are listed 'Best First'.
Re: What's wrong with my forwarder?
by bowei_99 (Friar) on Mar 31, 2006 at 07:28 UTC
    I can't see anything wrong with line 29. It seems ok, according the Net::Cmd and Net::SMTP docs.

    However, if you've added a couple lines since you got the error message you noted, I think it could be your statement in line 31-

    close OUT;
    Two things-
    1. Where do you open a filehandle called OUT? You can't close something you didn't open.
    2. Did you mean to close STDERR instead? If so, you may want to close it after the loop, as the way you have it it would close it right after deleting the message.

    Also, you should have the following lines at the beginning of your code. It will catch more errors -

    #!/usr/bin/perl -w use strict; use warnings;
    (replace your current #!perl line with #!/usr/bin/perl -w)

    -- Burvil

      OK, fixed those errors but it hasn't helped any - the problen's definitely with the line
      $smtp->dataend();
      and strict/warnings doesn't catch anything else. One line test e-mails seem to get forwarded fine while longer ones are more likely to fail, if that's any help.
Re: What's wrong with my forwarder?
by educated_foo (Vicar) on Apr 01, 2006 at 14:51 UTC
    I think the problem is you're printing a single "." on a line in one of your datasend()s. That's SMTP protocol for "end of message", so by the time you call dataend(), the SMTP server thinks the message has already finished.