Some servers do not accept mail from the server: Domain not found (in reply to RCPT TO command)

eximpostfix

I have the following problem. I use Gmail mail services for my domain name mydomain.com. My server with hostname server.my-datacenter.net sends messages to the users of my website with "from" and "reply-to" address info@mydomain.com. Postfix (and Exim on my second server) automatically adds email addresses root@server.my-datacenter.net or www-data@server.my-datacenter.net to all outgoing emails.

Some mail servers are not accepting emails from my server because server.my-datacenter.net itself does not accept mail. I can not create MX records for server.my-datacenter.net to make my server accept external emails because this domain/subdomain belongs to my data center and was assigned automatically as a hostname. I can not change hostname from server.my-datacenter.net to mydomain.com because in this case I can not have PTR record (my datacenter wants 5 EUR/month for a custom PTR record).

Server's IP address has a reverse PTR record to server.my-datacenter.net. Domain name mydomain.com has a SPF record (included Gmail + my server's IP address).

What can I do in this situation? Is it possible to force Exim and Postfix to use root@mydomain.com and www-data@mydomain.com instead of root@server.my-datacenter.net and www-data@server.my-datacenter.net? If yes, how can I do it in Postfix and Ensim.

If I do it, is it OK that outgoing email will contain email addresses with a different domain (not a server's hostname)?

2DBF7646459     1219 Wed Feb 20 11:46:01  root@server.my-datacenter.net
(host a.mail.server[xxx.xxx.xxx.xxx] said: 450 4.1.8 <root@server.my-datacenter.net>: Sender address rejected: Domain not found (in reply to RCPT TO command))
                                         email@address

Best Answer

Since you didn't explicitly set the hostname to use, exim when it starts up makes a valiant effort to figure it out from the hostname of the machine and/or the IP address. To override this in exim, explicitly set what you want it to be. Add to the global section of your config:

primary_hostname = mail.mydomain.com

...which assumes that hostname mail.mydomain.com resolves to the IP address of your mail server. Now when it receives email from non-qualified users, it will append @mail.mydomain.com instead of @server.my-datacenter.net.