richardp
By:
richardp

Postfix stuck in an unstoppable email loop to itself?

January 27, 2017 890 views
Email Ubuntu 16.04

I have an issue I can't figure out, and that is why postfix is constantly emailing itself, like it is stuck in an unstoppable mail loop?

I can see from the email log that the email is bouncing, because of an unknown user:

Jan 27 02:35:17 mydomain postfix/local.... to=<inquiry@mydomain.com>, relay=local, delay=0.01, delays=0/0/0/0, dsn=5.1.1, status=bounced (unknown user: "inquiry")

But the email exist and the email is used for sending out emails via a contact form on the website, and the email is hosted at Office 365.

I've figured out that there might be an issue with the website domain name and the email domain name being the same (externally set up at Office 365), so is there anyone who has experienced the same issue and how to correct it?

Is there anything in my /etc/postfix/main.cf file that should be different to prevent this?

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
relayhost = [smtp.office365.com]:587
myhostname = mydomain.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
2 comments
  • Someone suggested the following:

    Tell your web server that it's not responsible for the mail of mydomain.com (add the domain to /etc/remotedomains) then send out from inquiry@mydomain.com via your exim/smtp service.

    If my website domain is http://mydomain.com, my emails hosted externally via Office 365 and the MX record is set to 0:mydomain.com01b.mail.protection.outlook.com, how will the changes in /etc/remotedomains, help me?

    Or is the issue still in the configuration of postfix?

  • I've investigated this a bit and I figured out that postfix and the relay server (Office 365) is working perfectly fine, if the email recipient and sender is not the same.

    This works perfectly fine

    sender: inquiry@mydomain.com
    recipient: inquiry@gmail.com
    

    This makes postfix go bananas and it starts to bombard itself with bouncing emails

    sender: inquiry@mydomain.com
    recipient: inquiry@mydomain.com
    

    What do I need to change, and how can I make sure that the sender and recipient can be the same email address?

3 Answers
richardp January 30, 2017
Accepted Answer

I'm not sure if others have experienced this issue, but if your email server is hosted on another domain and you use postfix and SMTP to send local emails from a web form, then you need to setup the following in your postfix configuration.

myhostname = localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

This forces postfix to always use the external email server, even in a case the email recipient is under your local domain name, like myself@mydomain.com.

Please also male sure that $mydomain is equal to localdomain and it can be checked with postconf -d | grep mydomain, otherwise you can set the variable with mydomain = localdomain.

@richardp

When it comes to e-mail, there's two files localdomains and remotedomains (both in /etc).

When an e-mail is sent out, these two files are checked. If the domain is in localdomains, the mail gets routed locally -- if the domain is in remotedomains, the mail is routed off the server.

Since you're using an external mail server, I would remove your domain from the local to the remote file. You shouldn't need to restart any services as these files are checked each time and e-mail is sent.

  • I did not have any of these two files /etc/localdomains or /etc/remotedomains on the server, but I've just tried to add the domain mydomain.com to the remotedomains file, without any success.

    The email is still bouncing around like crazy and my mail.log file is increasing in file size with x amount of megabyte each minute.

    For your information, postfix is successfully sending out an email from the contact form via smtp and Office 365, and it reaches the destination, but after that, it starts to loop around in this evil bounce process?

I figured out that if the recipient is an email with the same domain name inquiry@mydomain.com as the website itself www.mydomain.com, postfix starts to constantly emailing itself and it get stuck in an unstoppable email loop.

So to prevent this, how can I set up postfix to always use "postfix/smtp" instead of "postfix/local", which clearly is causing the email bounce loop??

Have another answer? Share your knowledge.