12

My setup: I'm running a Magento website on an Amazon Linux server (which seems to basically be CentOS) with an Apache webserver. I also use Google Apps for managing mydomain.com's mail.

I was able to successfully set up the MX, SPF and DKIM records for the server and got them working, so that I receive a "Pass" for both SPF and DKIM when I send emails. However, I've run into a strange problem I can't seem to get past --- part of the header for the emails I send seems to always say:

Received: (from apache@localhost) by mydomain.com 

I've searched high and low for a way to change this to use "mail@mydomain.com" instead, but I just can't seem to figure it out.

Among things I've tried:

  • Changing the php.ini to say: /usr/sbin/sendmail -t -i -f mail@mydomain.com
  • Adding to mydomain.conf's virtualhost the line: ServerAdmin mail@mydomain.com
  • Setting the Return-Path to "Yes" in the Magento backend (System -> Configuration -> Advanced -> System -> Mail Sending Settings.

If it helps, the contents of my /etc/hosts file are as follows:

127.0.0.1   www.mydomain.com
127.0.0.1   mydomain.com
127.0.0.1   localhost localhost.localdomain

For the last line of the hosts file, I also tried the variation...

127.0.0.1   localhost.localdomain mydomain.com

...but it still didn't work.

I thought it might also help if I added the headers of the email, in case that might give some clues to what might be going on (I've changed a lot of values to keep it generalized).

Delivered-To: zerowing@email.com
Received: by 123.123.123.123 with SMTP id abcdefg123456790;
        Fri, 3 Apr 2015 08:35:04 -0700 (PDT)
X-Received: by 456.456.456.456 with SMTP id asdfqwerhjkl234hjkl.789.78909876789;
        Fri, 03 Apr 2015 08:35:03 -0700 (PDT)
Return-Path: <mail@mydomain.com>
Received: from mydomain.com (ec2-11-11-111-11.amazonaws.com. [66.66.777.77])
        by mx.google.com with ESMTPS id asdkfjhkjdfha839383.105.2015.04.03.08.35.02
        for <zerowing@email.com>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 03 Apr 2015 08:35:03 -0700 (PDT)
Received-SPF: pass (google.com: domain of mail@mydomain.com designates 66.66.777.77 as permitted sender) client-ip=66.66.777.77;
Authentication-Results: mx.google.com;
       spf=pass (google.com: domain of mail@mydomain.com designates 66.66.777.77 as permitted sender) smtp.mail=mail@mydomain.com;
       dkim=pass header.i=@mydomain.com
Received: from mydomain.com (www.mydomain.com [127.0.0.1])
    by mydomain.com (8.14.4/8.14.4) with ESMTP id t33FZ29p004251
    for <zerowing@email.com>; Fri, 3 Apr 2015 15:35:02 GMT
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mydomain.com;
    s=default; t=fjIFDJF9049;
    bh=fjO4J4f09j409JF04J909f4j904JF940F9/Y=;
    h=To:Subject:From:Date;
    b=F4J90FJ490j09j490FJ094J0j94f90j409j490Jf90j904JF09j490fj904jf094J
     f09J40F9J904fj049J099j49J049J0FJijffjdlfjldkDLFJKLdjflEJFOIJFOEIEO
     JF9JF049j409j0F094J09FJ049jf049j=
Received: (from apache@localhost) <----------- THIS IS WHAT I'M TRYING TO CHANGE
    by mydomain.com (8.14.4/8.14.4/Submit) id fkdjfljlfsra39393;
    Fri, 3 Apr 2015 15:35:01 GMT
Message-Id: <201504031535.fkdjfljlfsra39393@mydomain.com>
To: =?utf-8?B?Sm9lIEdhcmNpYQ==?= <zerowing@email.com>
Subject: =?utf-8?B?VGVzdCBOZXdzbGV0dGVyLCBwbGVhc2UgaWdub3Jl?=
X-PHP-Originating-Script: 48:Sendmail.php
From: "mydomain.com" <mail@mydomain.com>
Date: Fri, 03 Apr 2015 15:35:01 +0000
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
MIME-Version: 1.0

Part of me isn't sure if this is normal, and I guess I'm not sure what might be causing the apache@localhost to appear, but if anyone has an idea it would be much appreciated, thank you!

Edit The MTA I'm using is Sendmail. Here are the configuration changes I've made to the sendmail.mc file to accommodate for my site.

MASQUERADE_AS(`mydomain.com')dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
INPUT_MAIL_FILTER(`opendkim', `S=inet:8891@127.0.0.1')
define(`confCW_FILE', `/etc/mail/local-host-names')dnl
dnl define(`confDOMAIN_NAME', `mydomain.com')dnl

Edit I'm not sure if this question got marked as a duplicate again, so I thought I should emphasize the reasoning why it's not based on the referred question as to why it isn't. Switching to Postfix isn't a solution, so much as a workaround. I would hate to uproot all the setup I've done with Sendmail so far only to encounter other potential problems trying to get Postfix to work instead. I also already mentioned editing the sendmail command in php.ini, if you read the bullet points I mentioned above.

Edit I figured I might as well mention some of the other things I tried doing that didn't work. I added to my sendmail.mc the following lines:

FEATURE(`genericstable',`hash -o /etc/mail/genericstable.db')dnl
GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl

I then created a generics-domains file with the single line "mydomain.com" inside of it. Then, I created a genericstable file with the single line "apache mail@homebrewsupply.com" inside of it. I ran make in the mail directory, recreated the cf file, and restarted sendmail, but no dice.

I tried editing the /etc/aliases file. I tried changing the line "apache: root" to say "apache:root,mail@mydomain.com", as well as just "apache:mail@mydomain.com", but that didn't do anything either.

I also tried adding to the /etc/mail/virtuserstable file the single line "apache@localhost mail@mydomain.com". That didn't do anything either.

I'm surprised at how frustrating it is to get this working properly. I'm so close to having it where I need it, but I honestly don't know where to being looking to get the "apache@localhost" line replaced.

Zero Wing
  • 251
  • 1
  • 2
  • 4
  • Duplicate of http://serverfault.com/questions/254109/apache-sendmail-trying-to-change-user-from-address-from-apache-to-domain-acco and http://serverfault.com/questions/484777/how-to-configure-a-real-domain-name-for-sender-address – Mike B Apr 04 '15 at 15:27
  • Well for one, the solutions to those questions don't work for me. The first solution boils down to "I couldn't figure out how to get sendmail to work, so I gave up and switched over to postfix instead". That's not a solution to the problem, it's a workaround. The second solution, for adding the servername to the hosts file, also didn't work for me --- so essentially the problem I'm experiencing must be different. And it's not like I can wait for someone to add other workable solutions to questions that are over 2 years old. – Zero Wing Apr 04 '15 at 17:04

4 Answers4

4

The from email address is the user of the daemon that called for the message to be sent (apache) @ the domain name configured in your MTA (either sendmail or postfix).

If your local MTA is postfix, you need to change the myorigin setting (which defaults to the configured hostname. localhost in this example). This setting is in the main.cf (default location in most distributions is /etc/postfix/main.cf). Just change that to the domain name you want it to send from. Then restart postfix.

Of course, it may be easier for you to just change the hostname of the server to match the desired sending domain.

Keep in mind, that if you are going to send email from this server for that domain, you will want to add a SPF DNS record allowing it, otherwise your messages will likely get dumped by spam filters.

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
Joe
  • 1,023
  • 8
  • 11
  • Hi, my MTA is actually sendmail, though I think I've made all the possible adjustments to it that can be made (I'll try adding some of those changes to my question). Could you also clarify on "changing the hostname of the server to match the desired sending domain?" If you mean I should make it so that when I type "hostname" on the command line so that it outputs mydomain.com, I already have that set up. And also, I do have an SPF record set for the domain, I mentioned in the question that I have the SPF and DKIM set up and working successfully (I see a pass for both in my email headers). – Zero Wing Apr 03 '15 at 23:42
  • Found a post that might help suggesting the following: To change the envelope "from" address on unix, you specify an "-r" option to your sendmail binary. You can do this globally in php.ini by adding the "-r" option to the "sendmail_path" command line. source: http://stackoverflow.com/questions/5666312/php-mail-issue-with-www-data – Joe Apr 06 '15 at 15:20
  • I tried adding "-r" to the "sendmail_path" in my php.ini, but this seemed to break something, since mail suddenly stopped sending out from the server. More specifically, I changed the line to --- sendmail_path = /usr/sbin/sendmail -t -i -r mail@mydomain.com, but it still didn't work (I tried with and without quotation marks, and also made sure to restart the server, but no dice, and I'm not sure what was preventing it from being able to send emails after that point). – Zero Wing Apr 06 '15 at 17:40
3

In looking over your config it seems there are a couple of bits missing (and sorry for my syntax, I don't post often):

You'll probably want to add the MASQUERADE_DOMAIN config option to go with MASQUERADE_AS, matching the MASQUERADE_DOMAIN to whatever the FQDN of the host is (hostname -f on most linux platforms). I've had it do strange things if they're not both there, so it would be:

MASQUERADE_AS(`mydomain.com')dnl
MASQUERADE_DOMAIN(`fqdnname.internal')dnl

and then this line:

dnl define(`confDOMAIN_NAME', `mydomain.com')dnl

Should really be

define(`confDOMAIN_NAME', `mydomain.com')dnl

or it will be ignored by the make/hash commands when you update the sendmail.cf file. This guy gives a great explanation of why What is the difference between "dnl" and "dnl #" in a sendmail.mc file?

I'm still trying to get rid of the "apache" part in my own server, but I hope this gets you a little closer!

1

System -> Configuration -> Advanced -> System -> Set Return-Path -> Yes

or set it to email that you want to use. Just found this today - apparently some of the emails were getting rejected by mailservers with strict rules (.edu, .gov...etc)

Kalvin Klien
  • 145
  • 7
  • Wasted hours trying to work out what why our SPF records were being ignored and e-mails were still be flagged as spoofed when sent from our site to us. Had a hunch it was the Received-From header which led me here. Your 30 second solution worked instantly and put an end to hours of frustration! Simplest solution for this issue & Magento on this page. Recommend you try this first before altering your server config. – Ashley Swatton Jan 16 '18 at 22:37
  • I recommend completely switching off server based email service and just use Sparkpost + smtpPro plugin. Works like a charm with 100,000 emails / month free. – Kalvin Klien Jan 16 '18 at 23:13
1

Add define(`confRECEIVED_HEADER', `internal info removed')dnl to submit.mc then generate .cf file and restart sendmail as usual.

Important: the file that should be edited in order for this to work is submit.mc, and NOT sendmail.mc. If you edit the sendmail.mc file instead, the Received header above the one you mentioned will be the one modified (that is Received: from mydomain.com (www.mydomain.com [127.0.0.1])).

Note: Instead of the literal string internal info removed you can reuse some of the info provided while hiding the sensitive one, for example: by $j id $i; $b to get by DOMAIN id ID; TIMESTAMP.

The above will remove/replace the information after the Received header you mentioned:

Received: (from apache@localhost) <----------- THIS IS WHAT I'M TRYING TO CHANGE
by mydomain.com (8.14.4/8.14.4/Submit) id fkdjfljlfsra39393;
Fri, 3 Apr 2015 15:35:01 GMT

See also similar question: How to remove Received: (from apache@localhost) and sendmail version from headers

Chris Dev
  • 117
  • 6