5

I've been trying to set up a debian mail server running postfix, but when I try to send mail via mail example@outlook.com the recipient sees the sender as hostname.domain.com. The hostname it sends does not have an A or MX record set up to it, it is just the /etc/hostname. I can manually set the sender to admin@mydomain.com if I send by logging in via telnet localhost 25.

my main.cf

myorigin = mydomian.com
myhostname = mail.mydomain.com
mydestination = mail.mydomain.com, mydomain.com, localhost, localhost.localdomain
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

smtpd_tls_cert_file=/etc/ssl/certs/mailcert.pem
smtpd_tls_key_file=/etc/ssl/private/mail.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_tls_security_level=may
smtpd_tls_protocols = !SSLv2, !SSLv3
local_recipient_maps = proxy:unix:passwd.byname $alias_maps

and mail.log when I send out an email

Aug  3 06:28:51 hostname postfix/pickup[7047]: 4D5432023A: uid=1000 from=<user@hostname>
Aug  3 06:28:51 hostname postfix/cleanup[7065]: 4D5432023A: message-id=<20140803042851.4D5432023A@mail.mydomain.com>
Aug  3 06:28:51 hostname postfix/qmgr[7048]: 4D5432023A: from=<user@hostname.mydomain.com>, size=339, nrcpt=1 (queue active)
Aug  3 06:28:52 hostname postfix/smtp[7067]: 4D5432023A: to=<destination@destinationserver.com>, relay=mail.destinationserver.com[IP]:25, delay=1.4, delays=0.11/0.01/0.49/0.78, dsn=2.0.0, status=sent (250 Queued (0.110 seconds))
Aug  3 06:28:52 hostname postfix/qmgr[7048]: 4D5432023A: removed

I've tried setting masquerade_domains = mydomain.com but it gets flagged as spam in thunderbird and gmail when I do this.

Headers from a message sent by my server:

    Return-Path: user@hostname.mydomain.com
Received: from mail.mydomain.com (DESTINATION [127.0.0.1])
    by mail.destination.com
    ; Sun, 3 Aug 2014 08:10:06 +0200
Received: by mail.mydomain.com (Postfix, from userid 1000)
    id 6D7A68033A; Sun,  3 Aug 2014 08:10:27 +0200 (CEST)
To: <destination@outlook.com>
Subject: test
X-Mailer: mail (GNU Mailutils 2.99.97)
Message-Id: <20140803061027.6D7A68033A@mail.mydomain.com>
Date: Sun,  3 Aug 2014 08:10:27 +0200 (CEST)
From: user@hostname.mydomain.com

fdsa
Mutt
  • 63
  • 1
  • 4
  • Can you post the headers of an outgoing mail with wrong domain as sender? It is not exactly clear to me which name/domain you mean. – sebix Aug 03 '14 at 09:16
  • Oh, and what's in your `/etc/mailname`, as you are on debian? – sebix Aug 03 '14 at 09:34
  • @sebix my /etc/mailname is mail.mydomain.com. I've added the headers into the body. – Mutt Aug 03 '14 at 09:48
  • What happens if you comment out `myorigin` in `main.cf`, set `/etc/mailname/` to `mydomain.com` and restart postfix? Additionally: You mention both `hostname.mydomain.com` and `mail.domain.com`, can you elaborate on what are the differences and purposes of these two domains? – sebix Aug 03 '14 at 10:16
  • @sebix I have no idea why, but changing `/etc/mailname` from `mail.mydomain.com` to `mydomain.com` fixed it! To answer your question `hostname.mydomain.com` does not have a purpose (or an A record), this is the first machine I have tried to run both a web and mail server on so I didn't want to make the hostname mail like I would've in the past if it was just a mail server. `mail.mydomain.com` has A and MX records on it. Thank you so much for your help, I spent 6 hours tearing my hair out on this! – Mutt Aug 03 '14 at 10:30
  • 1
    For me the `masquerade_domains = $mydomain` worked. No flagging as spam. It was easier to fix the cause of the false flagging than the annoying `@host.domain.tld`. – Avamander Apr 29 '17 at 00:07

2 Answers2

4

I'm on Ubuntu 14.04 and I have exactly the same symptom as yours. But my problem is resolved by specifying a "From:" header explicitly, e.g.

mail -aFrom:sender@somedomain.com ...

If the -a option is missed in above command, there will be the exact symptom as yours.

BTW, I use mailutils version 1:2.99.98-1.1 amd64

Robert
  • 261
  • 3
  • 8
3

On debian, the default sender's domain used is specified by /etc/mailname. AFAIK this is a Debian specific modification to postfix.

So it should be solved by filling /etc/mailname with mydomain.com. And myorigin in postfix defaults to /etc/mailname on debian, which also should be used in my opinion (so just delete this line).

sebix
  • 4,313
  • 2
  • 29
  • 47