Exim sends mail from apache@hostname instead of the hostname I’m defining

apache-2.2exim

Whenever I send mail via Exim, even if I set a from field, it always says the e-mail is from: apache@server.mydomain.com. Is there any way to make the from field work or at least change the default from address? Thanks.

Best Answer

Okay, looking at the class you've linked to - you should already be setting the From: header which gets you half way there. Chances are that you're seeing the emails coming through look something like this:

From: <senderofchoice@example.com>
Sender: <apache@example.com>
Return-path: <apache@example.com>

Which isn't great. It looks confusing to a lot of people and Outlook users also helpfully see such messages tagged as "Apparently From".

This is caused by Exim not permitting Apache (as a system account) from "spoofing" the From address. You can see in line 39 of that class that sendmail is called (the Sendmail binary is symlinked to Exim for historical reasons) something like so:

sendmail -f $fromEmail

This tells Exim to specify the envelope sender address which is by default restricted to UID 0. You can read the intricate details about this from the -f section of the Exim man page. In short can change this by permitting Apache to modify the envelope sender in exim.conf:

trusted_users = apache