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

How do you edit the return-path when using sendmail? I've been developing a form to allow the sending of a link to a friend and want to be able to control the return-path value so that if an invalid address is entered the mail is returned to an address of my choice. Is this possible. I have tried using the -f switch to no avail, does this clash with -t? Any one with any ideas? Thanks

Replies are listed 'Best First'.
Re: Setting the return path in Sendmail
by footpad (Abbot) on Mar 14, 2001 at 19:52 UTC
    As others have commented, you may find the CPAN modules make this easier to implement (I know I have).

    Currently, I'm using MIME::Lite, which let's you do something like this:

    my $sender = 'yourname@example.com'; my $msg = MIME::Lite->new( Type => 'TEXT', From => $sender, To => 'theirname@example.com', Subject => 'Simple Greeting' ReplyTo => $sender, ErrorsTo => $sender, Data => 'Greetings, Lifeform!' ); $msg->send_by_smtp( 'localhost' ) or die "Unable to send message; reason $!\n";

    Note: the above is off the top of my head, so there may be typos or other silly mistakes. If so, sorry.

    The interesting bit, I think, in the above is the ErrorsTo line. That seems to work, provided you take care to send it to an appropriate address. For example, I have a special mailbox devoted to those errors.

    MIME::Lite also offers several alternatives for sending. For details, check the docs.

    Hope this helps...

    --f

Re: Setting the return path in Sendmail
by azatoth (Curate) on Mar 14, 2001 at 18:07 UTC
Re: Setting the return path in Sendmail
by lhoward (Vicar) on Mar 14, 2001 at 18:29 UTC
    What you want to do is set the Sender. There are many better ways to send mail in perl besides calling sendmail. Most of the other methods let you set the sender easily. My favorites include MIME::Lite, Net::SMTP, and Mail::Sendmail. See the perl faq under sending email.
      Well, the "return path" is not a header field. It's more officially called the "envelope from", or "From_". And -f does in fact set it, if you're permitted by the configuration.

      Of course, with SMTP as your first hop rather than sendmail, to some degree you have much more flexibility, including setting envelope from/to independent of the header from/to and sender.

      -- Randal L. Schwartz, Perl hacker

Re: Setting the return path in Sendmail
by merlyn (Sage) on Mar 14, 2001 at 18:20 UTC