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

I'd appreciate any help to this problem that I am experiencing. I wrote a newsletter script that sends out a text e-mail newsletter to over a 1000 e-mail addresses. I am using the Mail::Mailer module and sending the newsletters through sendmail. Everything works fine with one exception. Bounce-backs are sent to nobody@<myserver>.com . These accumulate in root's e-mail account. I would like them to go to the return address on the e-mail instead. The header for these e-mails looks something like this:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Date: Wed, 20 Feb 2002 21:58:58 -0800 From: Mail Delivery Subsystem <MAILER-DAEMON@freshnews.com> To: nobody@freshnews.com Subject: Returned mail: see transcript for details Parts/Attachments: 1 Shown 9 lines Text 2 Shown 301 bytes Message, "Delivery Status" 3 Shown 19 KB Message, "FreshNews.com eNewsletter" 3.1 Shown 422 lines Text ---------------------------------------- The original message was received at Wed, 20 Feb 2002 21:58:58 -0800 from nobody@localhost ----- The following addresses had permanent fatal errors ----- sdfjlk@sdljfdlskfjlsdkj.com (reason: 550 Host unknown) ----- Transcript of session follows ----- 550 5.1.2 sdfjlk@sdljfdlskfjlsdkj.com... Host unknown (Name server: sd +ljfdlskfjlsdkj.com: host not found) [ Part 2: "Delivery Status" ] Reporting-MTA: dns; freshnews.com Arrival-Date: Wed, 20 Feb 2002 21:58:58 -0800 Final-Recipient: RFC822; sdfjlk@sdljfdlskfjlsdkj.com Action: failed Status: 5.1.2 Remote-MTA: DNS; sdljfdlskfjlsdkj.com Diagnostic-Code: SMTP; 550 Host unknown Last-Attempt-Date: Wed, 20 Feb 2002 21:58:58 -0800 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
It seems that it is using the web server (nobody) as the sender and when it returns @<myserver>.com is appended to it. Most frustrating. Here is the code that I am using:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ $form_address = "newsletter\@freshnews.com"; $to_address = "whatever\@whateadsflkj.com"; $subject = "test"; $mailer = Mail::Mailer->new("sendmail"); $mailer->open({ From => $from_address, To => $to_address, Subject => $subject }) or die "Can't open: $!\n"; print $mailer $body; $mailer->close(); +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Thanks for your help! Jon St. John

Replies are listed 'Best First'.
Re: Mail::Mailer Question
by vagnerr (Prior) on Feb 21, 2002 at 09:25 UTC
    Congrats on fixing it yourself via other routes.
    Another thing to possibly look at is that you seem to have a typo in you example code
    $form_address = "newsletter\@freshnews.com";
    Verses
    From => $from_address,
    You have form and from so it may have been due to the fact that you had an undefined reference use strict; and perl -w would pick this up for you :-)

    ---If it doesn't fit use a bigger hammer
Re: Mail::Mailer Question
by gellyfish (Monsignor) on Feb 21, 2002 at 09:42 UTC

    You can supply the sendmail options as part of the new() methods arguments - in this case you might want to set the envelope address with:

    my $mailer = Mail::Mailer->new('sendmail','-f','foo@wherever.com');

    /J\

Re: Mail::Mailer Question
by jonstjohn (Initiate) on Feb 21, 2002 at 06:06 UTC
    Looks like I solved my own problem. If you have a similiar problem, try using Mail::Sendmail -- it will automatically insert the from address into the e-mail header.
Re: Mail::Mailer Question
by gav^ (Curate) on Feb 21, 2002 at 14:21 UTC
    You might want to investigate the Mail::Bulkmail module which amongst other things supports enveloping.

    gav^

Re: Mail::Mailer Question
by Speedy (Monk) on Feb 21, 2002 at 14:25 UTC
    Try setting the “Sender” field as well as the “From” field. The sender field was designed as an option to handle transport problem notices when "Send" and "From" differ.

    From the RFC 822 Standard for the format of ARPANET text messages

    -----
    The "Sender" field mailbox should be sent notices of any problems in transport or delivery of the original messages. If there is no "Sender" field, then the "From" field mailbox should be used.

    The "Sender" field mailbox should NEVER be used automatically, in a recipient's reply message.

    If the contents of the "Sender" field would be completely redundant with the "From" field, then the "Sender" field need not be present and its use is discouraged (though still legal). In particular, the "Sender" field MUST be present if it is NOT the same as the "From" Field.

    -----

    Never confuse the finger pointing at the moon with the moon (Fallacy of Misplaced Concreteness)