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

sendmail supports a -V flag:

-V <envid> Set the original envelope id. This is propagated across SMTP to servers that support DSNs and is returned in DSN-compliant error messages.
.. which should result in a nice parsable string in bounce messages from compliant servers something like:
Original-Envelope-ID: <envid>

I've looked at Mail::Send, Mail::Sender and Mail::Sendmail, and can't see support for setting this in any of those. Does anyone know of a mail-sending module that does support this field?

Update: for clarification, this is talking about the ESMTP 'ENVID' command, as described in RFC 3461.

Hugo

Replies are listed 'Best First'.
Re: Sending mail: setting envelope id
by eXile (Priest) on Jun 03, 2004 at 15:12 UTC
    Hi, If I understand RFC3461 correctly the ENVID is just appended to the From-addres, their example is:
    <<< 220 Example.ORG SMTP server here >>> EHLO Example.ORG <<< 250-Example.ORG <<< 250-DSN <<< 250-EXPN <<< 250 SIZE >>> MAIL FROM:<Alice@Example.ORG> RET=HDRS ENVID=QQ314159 <<< 250 <Alice@Example.ORG> sender ok >>> RCPT TO:<Bob@Example.COM> NOTIFY=SUCCESS \ ORCPT=rfc822;Bob@Example.COM <<< 250 <Bob@Example.COM> recipient ok >>> RCPT TO:<Carol@Ivory.EDU> NOTIFY=FAILURE \ ORCPT=rfc822;Carol@Ivory.EDU
    so something like:
    use Net::SMTP; my $smtp = Net::SMTP->new('mail.example.org'); $smtp->ehlo(); $smtp->mail('<Alice@Example.ORG> RET=HDRS ENVID=QQ314159'); $smtp->to('RCPT TO:<Bob@Example.COM> NOTIFY=SUCCESS ORCPT=rfc822;Bob@E +xample.COM '); $smtp->data(); $smtp->datasend('To: Alice@Example.ORG'); $smtp->datasend('Subject: test'); $smtp->data(); $smtp->datasend($your_message_here); $smtp->dataend(); $smtp->quit();
    should do the trick. I haven't got a mailserver that supports the ENVID extension, so didn't test this.

      Thanks for the suggestion. Rolling my own SMTP connection in that way seemed like too much work, so I ended up instead implementing the encoding specified by RFC 3461, and writing a little argument quoter (similar to Aristotle's) to let me invoke sendmail with a 2-arg open. Here is (roughly) the encoder:

      sub _quote_envid { local $_ = shift; # RFC 3461: max 100 chars, pass through printable ASCII characters e +xcluding # [ =+], encode others to '+XX' as uc(hex(ord($char))) s{([^\x21-\x7e]|[=+]))}{sprintf "+%02X", ord($1)}ge; # we're usually encoding an email address, so trim long strings from + front # to preserve the domain s/^(\+..|.)// while 99 < length; $_; }

      Hugo

Re: Sending mail: setting envelope id
by hsinclai (Deacon) on Jun 03, 2004 at 14:48 UTC
    I know you asked about a module, sorry, and I don't know if you can do this in your application, but, remember the standard old way of piping the entire mail through your mailer program?

    In this way you can introduce header content at will.

    $envid = 'Original-Envelope-ID: <whatever-envid-is>'; chop(my $date = `date "+%m/%d/%y-%H:%M%p GMT-5"`) my $mailer = qx!which sendmail!; if ( $? eq 0 ) { $recip = 'thereal@domain.com'; $fromaddr = 'realname <bla@bla.net>'; $subject = "thesubject"; $xmailer = "cgi"; $mailmessage = qq| A text message... |; } else { $mailer = "failed"; }


    then,
    sub dispatch { open(MAILPIPE,"|$mailer"); print MAILPIPE "To: $recip\n"; print MAILPIPE "From: $fromaddr\n"; print MAILPIPE "Subject: $subject\n"; print MAILPIPE "Date: $date\n"; print MAILPIPE "$envid\n" if $envid; #here print MAILPIPE "X-Mailer: $xmailer\n"; print MAILPIPE "$mailmessage\n"; close(MAILPIPE); } &dispatch unless $mailer eq "failed";
Re: Sending mail: setting envelope id
by fuzzyping (Chaplain) on Jun 03, 2004 at 14:15 UTC

      Thanks, but this is not a mail header field. it is rather part of the envelope in a similar way to the 'From' envelope.

      Hugo