How to remove "via" from email From header?

May 1, 2017 476 views
Email Ubuntu

My droplet (Ubuntu 14.04) is hosting multiple websites using Apache virtual hosts. I have send-only Exim4 installed (for website contact forms, admin emails etc.) and I've set up SPF and DKIM records. Emails from all the websites are verified and do not end up with any flags or go into spam. Awesome!

However, emails from all websites except my main website (the one my droplet is named after) arrive with "From: Name <website@thisdomain.com> via hostname.maindomain.com".

How can I get rid of "via hostname.maindomain.com"?

My /etc/exim4/conf.d/transport/30_exim4-config_remote_smtp contains the following:

DKIM_DOMAIN = ${lc:${domain:$h_from:}}
DKIM_PRIVATE_KEY = /etc/exim4/dkim/{DKIM_DOMAIN}.pem
DKIM_SELECTOR = mail
DKIM_CANON = relaxed

In other words, all my websites are using the same DKIM keys. But that shouldn't make a difference, right?

2 Answers

Hi @jpgklassen

Looks like a good Exim setup. It has nothing to do with DKIM - not in this case.

I'm guessing you're using PHP. You need to change the MAILFROM address, so it doesn't automatically use your domain.
I don't know Exim, but I think it's a drop-in-replacement of Sendmail just like Postfix is.

You can modify the php.ini for each domain, or simply add the following to the root .htaccess file (there is a space after the -i in the end):

php_value sendmail_path /usr/sbin/sendmail -t -f website@thisdomain.com -i 
  • Ah nice, I didn't know about that php setting. But the emails from my various websites are all coming from the email addresses I want - wordpress@mydomain.com, website@mydomain2.com, etc. I don't want to change them. I just want to get rid of the "via hostname.mydomain.com" (FQDN) at the end, when I open the emails in ie. Gmail.

    Changing that php variable would change the email address the email is being sent from, right? That's not quite what I'm looking for.

    • You need to change your MAILFROM, since it's not the same as the From address.

      • Am I supposed to make it identical to the From address?

        • No, I don't think Gmail requires that to hide the "via". But it needs to be the same domain.

          • I see. So it sounds to me that there's no way for me to have multiple websites sending emails from multiple domains on the same server, without getting the "via". Do I have that right?

Hi @jpgklassen

To answer you question:
So it sounds to me that there's no way for me to have multiple websites sending emails from multiple domains on the same server, without getting the "via"

Yes, follow what I've written in the first answer - add the PHP value.
I'm running several servers with many websites on each server and all of them are setup like this.

Have another answer? Share your knowledge.