Can’t send mail to own domain. Postfix: status=bounced (unknown user: “user”)

Last updated on

Having problems sending email to your own domain? You may need to change your postfix configuration.

I was experiencing a problem sending mail to an address at my own domain. I wanted my PHP app to send notification emails to [email protected] but they kept bouncing with “status=bounced (unknown user: “user”)”.

Accessing the log:

sudo tail /var/log/mail.log -n 200

This will return the last 200 lines of the log.

Log output:

/var/log/mail.log
May 24 12:28:04 example postfix/pickup[30776]: DC48FC0927: uid=33 from=
May 24 12:28:04 example postfix/cleanup[32746]: DC48FC0927: message-id=<[email protected]>
May 24 12:28:04 example postfix/qmgr[1711]: DC48FC0927: from=<[email protected]>, size=9136, nrcpt=1 (queue active)
May 24 12:28:04 example postfix/local[32748]: DC48FC0927: to=<[email protected]>, relay=local, delay=0.06, delays=0.03/0.01/0/0.01, dsn=5.1.1, status=bounced (unknown user: "user")
May 24 12:28:04 example postfix/cleanup[32746]: E7413C0928: message-id=<[email protected]>
May 24 12:28:04 example postfix/qmgr[1711]: E7413C0928: from=<>, size=10993, nrcpt=1 (queue active)
May 24 12:28:04 example postfix/bounce[32749]: DC48FC0927: sender non-delivery notification: E7413C0928
May 24 12:28:04 example postfix/qmgr[1711]: DC48FC0927: removed
May 24 12:28:04 example postfix/local[32748]: E7413C0928: to=<[email protected]>, relay=local, delay=0.01, delays=0/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
May 24 12:28:04 example postfix/qmgr[1711]: E7413C0928: removed
May 24 12:28:04 example postfix/pickup[30776]: EBC48C0927: uid=33 from=
May 24 12:28:04 example postfix/cleanup[32746]: EBC48C0927: message-id=<[email protected]>
May 24 12:28:04 example postfix/qmgr[1711]: EBC48C0927: from=<[email protected]>, size=8898, nrcpt=1 (queue active)

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 PHP web form for example, then you need to setup the following in your postfix configuration.

Open your Postfix config file.

sudo nano /etc/postfix/main.cf

Scroll down and look for the entries for myhostname and mydestination. Change them so they look like this.

/etc/postfix/main.cf
. . .
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
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 [email protected]

Lastly, let’s restart Postfix.

sudo systemctl restart postfix

You can send a test email to see if it works.

echo "Test Email message body" | mail -s "Email test subject" [email protected]
1 Star2 Stars3 Stars4 Stars5 Stars 5.00 (13 votes)

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

p.s. I increased my AdSense revenue by 68% using AI 🤖. Read my Ezoic review to find out how.

11 replies

avatar
  Subscribe  
newest oldest
Notify of
jusdepixel
Guest
jusdepixel
jusdepixel
4 months ago

Thanks !!!

Borislav Jordanov
Guest
Borislav Jordanov
Borislav Jordanov
4 months ago

Thanks for making it simple! I went through very complicated configurations and couldn’t see what was wrong with mine until I saw this one.

Thomas | Code Sheep
Guest
Thomas | Code Sheep
Thomas | Code Sheep
7 months ago

Dude, you are awesome. Your articles have saved my butt more than a few times, thanks!!

Jakke Lehtonen
Guest
Jakke Lehtonen
Jakke Lehtonen
9 months ago

If I’m right this happends only when hostname is same as domain. And it should not be because then FQDN breaks. So, if your domain is example.com and you want get something informatic in the beginning of SSH-commandline you should use somethinglike example as hostname.

ax9g9n
Guest
ax9g9n
ax9g9n
9 months ago

Works like a charm, thanks a lot .

Crealogic
Guest
Crealogic
Crealogic
10 months ago

Quick, accurate, simply great. Thank you very much.

Kamrul Ahsan
Guest
Kamrul Ahsan
Kamrul Ahsan
1 year ago

Thanks man. Works great

DH
Guest
DH
DH
1 year ago

Like every other suggestion I can find. it doesnt work. The only way I can find to send to my own domain or relay to my own domain is to change the domain name in the hosts file. Then everything works

Rahul Bhayana
Guest
Rahul Bhayana
Rahul Bhayana
1 year ago

HI! It didn’t work for me. But I have a question, what happens if I keep mydestination header blank ?

Tim
Guest
Tim
Tim
1 year ago

Thanks a lot. Easy to understand, saved a lot time.