Mail is sent out from wrong IP address in Postfix

Created:

2016-11-16 12:52:44 UTC

Modified:

2017-08-16 16:19:27 UTC

1

Was this article helpful?


Have more questions?

Submit a request

Mail is sent out from wrong IP address in Postfix

Applicable to:

  • Plesk 12.5 for Linux
  • Plesk 11.x for Linux
  • Plesk 12.0 for Linux
  • Plesk 10.x for Windows

Symptoms

Outgoing mail mode setting in Tools and Settings > Server-Wide Mail Settings is set to Send from domain IP addresses and use domain names in SMTP greeting :

settings

However, when mail arrives to a recipient, it has wrong IP address in Received header.

Running mchk does not fix the issue.

Cause

Wrong IP addresses (IP address IDs) are defined for web service of the domain.

~# plesk db

mysql> SELECT d.name, s.type, a.ip_address FROM domains d JOIN DomainServices s ON d.id=s.dom_id JOIN IpAddressesCollections ipc ON s.ipCollectionId=ipc.ipCollectionId JOIN IP_Addresses a ON a.id=ipc.ipAddressId;

The output looks like this:

...
| example.com | mail | 203.0.113.2 |
| example.com | web | 203.0.113.3 |

...

Note, that IPs are different for mail and web (both IPv4 and IPv6).

Resolution

Change IP address of mail service wit the command:

# plesk bin domain -u example.com -mail-service-ip <needed_IP>

If it doesn't help try following:

  1. Take a backup of Plesk database and Postfix configuration:

    ~# mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` psa > psa.`date +%F.%s`.sql
    ~# cp /etc/postfix/master.cf{,.bck}
  2. Execute the following queries in Plesk database:

    mysql> BEGIN;
    mysql> CREATE TEMPORARY TABLE v4 SELECT s.dom_id, i.*, a.ip_address FROM DomainServices s JOIN IpAddressesCollections i ON s.ipCollectionId=i.ipCollectionId JOIN IP_Addresses a ON i.ipAddressId = a.id WHERE ip_address rlike '[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}' AND s.type='mail';

    mysql> CREATE TEMPORARY TABLE v6 SELECT s.dom_id, i.*, a.ip_address FROM DomainServices s JOIN IpAddressesCollections i ON s.ipCollectionId=i.ipCollectionId JOIN IP_Addresses a ON i.ipAddressId = a.id WHERE ip_address NOT rlike '[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}' AND s.type='mail';

    mysql> SELECT * FROM v4 JOIN v6 ON v4.dom_id = v6.dom_id;

    mysql> UPDATE v4 SET ipAddressId = COALESCE((SELECT ipAddressId FROM DomainServices s JOIN IpAddressesCollections i ON s.ipCollectionId = i.ipCollectionId JOIN IP_Addresses a ON i.ipAddressId = a.id WHERE s.dom_id=v4.dom_id AND ip_address rlike '[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}' AND TYPE='web'),0);

    mysql> UPDATE v6 SET ipAddressId = COALESCE((SELECT ipAddressId FROM DomainServices s JOIN IpAddressesCollections i ON s.ipCollectionId = i.ipCollectionId JOIN IP_Addresses a ON i.ipAddressId = a.id WHERE s.dom_id=v6.dom_id AND ip_address NOT rlike '[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}' AND TYPE='web'),0);

    mysql> SET @id = (SELECT v4.dom_id FROM v4 JOIN v6 ON v4.dom_id = v6.dom_id WHERE v4.ipAddressId=0 AND v6.ipAddressId=0);

    mysql> DELETE FROM v4 WHERE dom_id=@id;

    mysql> DELETE FROM v6 WHERE dom_id=@id;

    mysql> DELETE FROM IpAddressesCollections WHERE ipCollectionId IN (SELECT ipCollectionId FROM v4);

    mysql> DELETE FROM IpAddressesCollections WHERE ipCollectionId IN (SELECT ipCollectionId FROM v6);

    mysql> INSERT INTO IpAddressesCollections (SELECT ipCollectionId, ipAddressId FROM v4);

    mysql> INSERT INTO IpAddressesCollections (SELECT ipCollectionId, ipAddressId FROM v6);
    mysql> COMMIT;
  3. Rebuild mail configuration:

    ~# /usr/local/psa/admin/sbin/mchk --without-spam
  4. Make sure that /etc/postfix/master.cf does not contain old invalid entries for particular domain.

Additional info

#213398589 How to configure the IP address for outgoing mail in Postfix

Have more questions? Submit a request
Please sign in to leave a comment.