Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How do I rewrite mail headers using Mail::Send?

by djantzen (Priest)
on Jun 25, 2002 at 04:13 UTC ( [id://177027]=note: print w/replies, xml ) Need Help??


in reply to How do I rewrite mail headers using Mail::Send?

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!

Replies are listed 'Best First'.
Re: Re: How do I rewrite mail headers using Mail::Send?
by linebacker (Scribe) on Jun 25, 2002 at 17:11 UTC
    Mail::Mailer allows you to set the type of mail server you are using. It checks mailx, Mail and mail in that order if you do not specify the $type. So, in other words to change this default behavior from mailx Mail and mail to smtp a snippet might look like:
    use Mail::Mailer; use Mail::Mailer qw(mail); $mailer = new Mail::Mailer; $mailer = new Mail::Mailer 'smtp', Server => $server; $mailer->open(\%headers); print $mailer $body; $mailer->close;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://177027]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-26 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found