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

Hi, This script perfectly runs except one thing: in MS outlook, the body is empty. It ends up into header (I saw it in the header part). But it perfectly show up in Yahoo mail. Any thought about it? Thanks in advance.
#------------- sub routine ------------------------------------------# #need parameters: server,sender,recipient,subject,content sub send_result_by_email { my ($server,$sender,$recipient,$subject,$content) = @_; print "$server $sender $recipient $subject $content \n"; #print "$server \n"; #my $s = new Net::SMTP($server); #my $s = Net::SMTP->new($server,Timeout => 60); $s = Net::SMTP->new($server, Hello =>'my.mail.domain', Timeout =>30, Debug =>1, ); if ($s) { $s->mail($sender); #if (!$s->ok()) { # my $msg = $s->message(); # chomp ($msg); # print "$server:$msg"; # return 1; #} $s->to($recipient); # if (!$s->ok()) { # my $msg = $s->message(); # chomp ($msg); # print "$server:$recipient:$msg"; # return 1; #} $s->data(); $s->datasend("From: $sender\n"); $s->datasend("To:$recipient\n"); # $s->datasend ("Date: $datesent\n"); # $s->datasend ("Message-Id: $anything\n"); $s->datasend("Subject: $subject\n"); $s->datasend("$content\n"); # $s->datasend(".\n"); $s->dataend(); # if (!$s->ok()) { # my $msg = $s->message(); # chomp ($msg); # print "datasend $server $recipient:$msg"; # return 1; # } $s->quit; return 0; } else { print "Can't create new SMTP object.\n"; return 1; }

Replies are listed 'Best First'.
Re: about Net::SMTP
by mattriff (Chaplain) on Apr 24, 2002 at 00:02 UTC
    I believe you need to add a second newline after the Subject, like:
    $s->datasend("Subject: $subject\n\n");

    Some mail clients (maybe most, I dunno) need to see a completely blank line to separate the headers from the message body.

    - Matt Riffle

Re: about Net::SMTP
by gav^ (Curate) on Apr 24, 2002 at 00:03 UTC
    You seem to be missing a $s->datasend("\n") between your headers and the body.

    gav^

Re: about Net::SMTP
by perlplexer (Hermit) on Apr 24, 2002 at 00:04 UTC
    Put two (2) "\n"s after the subject line:
    # ... $s->datasend("To:$recipient\n"); $s->datasend("Subject: $subject\n\n"); # here $s->datasend("$content\n"); # ...
    --perlplexer
Re: about Net::SMTP
by jsprat (Curate) on Apr 24, 2002 at 00:06 UTC
    You need an extra "\n" between the headers and the body.

    HTH

    UPDATE: Amazing how quickly you guys answered this one!