I ran into this problem just the other day. Under the covers all Mail::Send does is pass the header's hash to a Mail::Mailer::* subclass and then to a platform specific program like sendmail.

Check to see if the exact subclass of Mail::Mailer you're using is smtp. If so, it's using Mail::Util::mailaddress to set the 'From' value in the method set_headers.

Mail::Util docs:

Return a guess at the current users mail address. The user can force the return value by setting $ENV{MAILADDRESS}

Update: This is the code for set_headers, which I just noticed overwrites the value returned by mailaddress with the value of 'From' (if specified) in the headers:

$self->SUPER::set_headers({ From => "<" . mailaddress() . ">", %$hdrs, 'X-Mailer' => "Mail::Mailer[v$Mail::Mailer::VERSION] Net::SMTP +[v$Net::S\ MTP::VERSION]"

I should note that although I encountered this problem a couple days ago, I haven't yet solved it! ;)

UPDATE: Aha! I think I've got it. I was mistaken in thinking that sendmail was the mail program it was defaulting to. In fact, it was running mailx. Now, you can force it to use sendmail by passing the string 'sendmail' when you call Mail::Send::open. Doing so will (probably) enable you to set the 'From' value successfully.

I believe that the reason the 'From' header gets changed has to do with /etc/mail/mailx.rc which (on my system (Solaris 8)) lists quite a number of allegedly "uninteresting" headers to ignore. I don't see 'From' specifically, but there are a couple of other likely candidates there. So, I think it wipes out the value submitted via Mail::Send/Mailer and resets it with the 'username@hostname' combination.

Whew! Sorry for the stream of consciousness answer -- I just kept thinking I'd figured out the problem!


In reply to Re: How do I rewrite mail headers using Mail::Send? by djantzen
in thread How do I rewrite mail headers using Mail::Send? by c

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.