I just thought I would blog this so that people can find it in a search, as I could not when I tried.
I have a perl script on a machine that sends out transactional emails with the from address like email@example.com. The machine it sends from is not example.com. Let’s call it admin.foobar.example.com. Since some misguided people think that sender verification callouts are a good idea, their MX hosts try to connect to admin.foobar to see if the billing address is there and accepting mails. This fails because admin.foobar does not run a public MTA and I do not want it to run one either.
It’s clear that the correct thing is for the script to be setting its envelope sender to firstname.lastname@example.org since email@example.com should be an email address that does actually work! How to do it with perl’s Mail::Send, however, is not so clear.
After trying to work this out myself for a few hours I asked dg, who is not just a perl monger but a veritable perl Tesco, making mere perl mongers compromise on their margins and putting many of them completely out of business. Every little helps.
Based on his reading of the source of Mail/Util.pm, he thought it might be accomplished by setting the MAILADDRESS environment variable. He was wrong however:
<dg> oh, that only works for SMTP
<dg> how crap
The next suggestion was a no-go also, but third time lucky:
<dg> actually, $msg->open("sendmail", "-f ...");
and that works. So there you go.