in reply to Net::SMTP - To: and From: not appearing in headers?

The problem may be related to you forgetting to separate your header lines.

EDIT: Here's what I use:

$smtp->datasend("From: $from\n\r" . "Return-Path: $from\n\r" . "Reply-To: $from\n\r" . "To: $to\n\r" . "Subject: $subject\n\r\n\r" . $message);
EDIT: atcroft is right that header lines should be separated by CRLF instead of just \n (does it matter if it's \r\n or \n\r?) That changes my code to the above. Note the Return-Path btw - you don't want any rejected emails to get sent to a black hole instead of your primary email.

Replies are listed 'Best First'.
Re^2: Net::SMTP - To: and From: not appearing in headers?
by nobull (Friar) on May 30, 2005 at 14:28 UTC
    Not that this has anything to do with Perl but the Return-path header is not a real SMTP header and you should not include it in your calls to $smtp->datasend().

    The Return-path header is added by the final destination MTA and contains the copy value of the actual return path, otherwise known as the envelope from address. In terms of Net::SMTP this is the value that was specified using $smtp->mail($from).

Re^2: Net::SMTP - To: and From: not appearing in headers?
by ghenry (Vicar) on May 30, 2005 at 09:21 UTC

    Thanks.

    I'll try swapping out the commas for semi-colons on the To: and From: lines on the datasend lines.

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!
      Actually you have to end every line of $smtp->datasend() with a ';' cause they are Different lines.
      They are not part of the 'new' method
      Also you should have your $to and your $from variables with the actuall email address, not what appears on the email.
      So your code should look like this
      my $to = "ghenry\@perl.me.uk"; my $from = "support\@perl.me.uk"; my $server = "relay.plus.net" ; $smtp = Net::SMTP->new($server); $smtp->mail($from); $smtp->to($to); $smtp->data(); $smtp->datasend("To: Gavin Henry <$to>\n"); $smtp->datasend("From: Support <$from>\n"); $smtp->datasend("Subject: Rsync backup success on $date\n"); $smtp->datasend("The remote backup has been completed.\n\n"); $smtp->datasend("Info:\n"); $smtp->datasend("\n$rsync\n"); $smtp->dataend(); $smtp->quit;

      I also added a quit, to the smtp object, unless you intent to do anything else with it and the socket connection.

      ``The wise man doesn't give the right answers, he poses the right questions.'' TIMTOWTDI
Re^2: Net::SMTP - To: and From: not appearing in headers?
by ghenry (Vicar) on May 30, 2005 at 09:42 UTC

    Cheers,

    It doesn't like CRLF, but newlines work fine.

    The only problem now is the date field is blank, i.e. when it was received.

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!

      The date field would be blank because you did not include the originating date (a Date: line) in the headers. The format for the date is in section 3.3 (pages 13 and 14) of the aforementioned RFC.

      Hope that helps.

        Ah!

        I thought the date was the date my e-mail server received the e-mail?

        Walking the road to enlightenment... I found a penguin and a camel on the way.....
        Fancy a yourname@perl.me.uk? Just ask!!!