I have been noticing for a while that whenever my web server wants to send e-mail (some PHP applications send mail), it always appears to come from apache@localhost.localdomain. I never really bothered to look into this, until my Yahoo mail started filtering these messages as spam.
The headers of the message (before) were
X-Apparently-To: mpicker0@yahoo.com via 66.163.169.92; Thu, 24 Jun 2004 05:33:56 -0700 X-Originating-IP: [24.129.197.12] Return-Path: <root@localhost.localdomain> Received: from 24.129.197.12 (EHLO localhost.localdomain) (24.129.197.12) by mta200.mail.dcn.yahoo.com with SMTP; Thu, 24 Jun 2004 05:33:56 -0700 Received: (from root@localhost) by localhost.localdomain (8.11.6/8.11.6) id i5OCXte05504 for mpicker0@yahoo.com; Thu, 24 Jun 2004 08:33:55 -0400 Date: Thu, 24 Jun 2004 08:33:55 -0400 From: "root" <root@localhost.localdomain> Add to Address Book Message-Id: <200406241233.i5OCXte05504@localhost.localdomain> Content-Length: 13
What I really want is for the mail to come from apache@mpickering.homeip.net. I started researching how to do this, but kept running into dead ends until I found this link on sendmail's site. It reads, in part,
In some (fairly rare) cases, gethostbyname may fail to return the FQDN.
I guess gethostbyname is returning localhost.localdomain on my server; probably because I haven't configured it to know about its external DNS address.
Like many solutions given on my Wiki, I don't know if this is the "proper" method for making this work. It does work, though, which is the critical part for me.
Then, I regenerated /etc/sendmail.cf (you should probably back it up first) by running
m4 /etc/mail/sendmail.mc > /etc/sendmail.cf
and finally, restarted sendmail with
/sbin/service sendmail restart
X-Apparently-To: mpicker0@yahoo.com via 66.163.170.248; Thu, 24 Jun 2004 08:09:11 -0700 X-Originating-IP: [24.129.197.12] Return-Path: <root@mpickering.homeip.net> Received: from 24.129.197.12 (EHLO mpickering.homeip.net) (24.129.197.12) by mta101.mail.scd.yahoo.com with SMTP; Thu, 24 Jun 2004 08:09:11 -0700 Received: (from root@localhost) by mpickering.homeip.net (8.11.6/8.11.6) id i5OF9Am06239 for mpicker0@yahoo.com; Thu, 24 Jun 2004 11:09:10 -0400 Date: Thu, 24 Jun 2004 11:09:10 -0400 From: "root" <root@mpickering.homeip.net> Add to Address Book Message-Id: <200406241509.i5OF9Am06239@mpickering.homeip.net> Content-Length: 13
In my searching, I found some good examples of setting up sendmail. Here's an old but good guide to setting it up, and testing it with telnet.