Having issues with Postfix sending out as user@hostname rather than

Posted June 9, 2017 39.8k views
EmailUbuntu 16.04
  1. I keep getting issues where postfix keep trying to send out as the hostname
  2. Is there a way to send out emails if the username is not on the server?

I’ve been following this guide: and looked through the comments. I’ve ended up adding

masquerade_domains =
myhostname =
mydomain =

And I checked /etc/mailname and it only has in it.


Jun  9 20:03:50 web-server postfix/master[2276]: terminating on signal 15
Jun  9 20:03:51 web-server postfix[2436]: Postfix is running with backwards-compatible default settings
Jun  9 20:03:51 web-server postfix[2436]: See for details
Jun  9 20:03:51 web-server postfix[2436]: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload"
Jun  9 20:03:51 web-server postfix/master[2473]: daemon started -- version 3.1.0, configuration /etc/postfix
Jun  9 20:03:56 web-server postfix/pickup[2474]: D62F51710A: uid=1001 from=<user@web-server>
Jun  9 20:03:56 web-server postfix/cleanup[2480]: D62F51710A: message-id=<>
Jun  9 20:03:56 web-server postfix/qmgr[2475]: D62F51710A: from=<user@web-server>, size=406, nrcpt=1 (queue active)
Jun  9 20:03:57 web-server postfix/smtp[2482]: D62F51710A: to=<>,[]:25, delay=0.43, delays=0.05/0.06/0.17/0.15, dsn=2.0.0, status=sent (250 2.0.0 OK 1497038637 w195si1953813qkb.93 - gsmtp)
Jun  9 20:03:57 web-server postfix/qmgr[2475]: D62F51710A: removed


# See /usr/share/postfix/ for a commented, more complete version

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

masquerade_domains =
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname =
mydomain =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname,, localhost, localhost.localdomain, localhost
relayhost =
mynetworks = [::ffff:]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
6 answers

Hi @tannerchung

Can you change the last section of /etc/postfix/ to this:

# where is the FQDN for the server
myhostname =
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = 
relayhost = 
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
mynetworks = [::ffff:]/104 [::1]/128
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all

@hansen I’m still getting the same issue even after changing for myhostname and adding and deleting the contents of the mydestination line. I made sure to restart postfix as well.

  • @tannerchung
    Then it’s probably your script that generates the mail that is causing the problem.
    What are you running. Which type of application do you need mails to be sent from?

@hansen well I’m only using echo “This is the body of the email” | mail -s “This is the subject line” like in the tutorial and I’m getting those issues.

I need to use it for WordPress basically - I wasn’t receiving any emails from WordPress, user creation etc.

@hansen do I need to change my hostname to match my domain name? I don’t know if that’s supposed to be how it works but maybe it’s a workaround?

@hansen /etc/hostname just has my hostname in it, not the domain.. should I change that?

I’ll look into SparkPost but I just like having the email sent via my own server so I don’t depend on a third party for now

  • @tannerchung

    As much as you may prefer to keep it local, I agree with @hansen and SparkPost (or a similar service with a WordPress plugin) is what I’d recommend as well.

    The main reason for this is because WordPress uses PHP’s mail function by default. The issue is that the function doesn’t authenticate anything for you and Postfix or Sendmail only acts as a relay.

    When an e-mail is sent without authentication and no verification (SPF, DKIM, DMARC, ect), providers such as Google, Yahoo, Microsoft (Outlook), ZoHo, and others will flag it, mark it as spam, toss it in the junk folder, or just reject it.

    This affects mail deliverability as well as credibility. Once you’re on a blacklist, it’s not always easy to get off of it.

    The purpose of SPF, DKIM, DMARC, and various other configurations, all of which can be setup to work with Postfix (but it’s a pain to manage), is to tell the receiving server that the domain that is sending the e-mail is valid and that whoever is sending is who they say they are. Without those things in place, you’re taking a shot in the dark as to whether the person you’re sending to will actually receive it.

    Transactional e-mail providers, such as SparkPost, alleviate those pain points by allowing you to use their SMTP servers, or API. You’ll confirm your domain, add their SPF/DKIM to your domain and then use the plugin to send through their API. This prevents you from having to manage a fully functional mail server on your end, and takes the pain out of mail delivery.

    • @jtittle I didn’t know SparkPost until you started recommending it, so thank you!

    • @hansen @jtittle Yes I regret trying to run this all on a 1gb server.. it started running out of memory and now I have to remove all these services just to reclaim some memory for WordPress..

      Although, I’m confused on why when I hit my domain with my current browser it is fine accessing it but when I hit it incognito it is a 500 error with apache error logs explaining a lack of memory.

      I supposed the caching I’ve setup is allowing me to hit the site still?

      • @tannerchung

        You should be able to run WordPress on 1GB without too much tweaking, but when you’re running Apache instead of Nginx, and Postfix, then you really have to watch your plugins+theme.

        It seems like a strange cache you’re running. It shouldn’t cache you, since you are logged into WordPress and always want up-to-date site content.
        What cache system have you setup?

      • @hansen I was using w3 total cache and got a little ambitious enabling pretty much everything. I’m starting to wonder if the 500 errors, “lack of RAM”, was caused by this but I decided to do a fresh install of everything and it’s all back to fast and normal. as an FYI a bare LAMP WordPress install with SSL is 204M right now

        Now to finally create a snapshot and install some plugins..

        • @tannerchung It’s difficult to say without running some diagnostics. It’s good to make use of the snapshots when testing (just remember to remove un-needed snapshots, since you pay for each).
          If you have more questions, then start a new question, so we don’t mix with this Postfix question. Use the @[username] to notify us.

@hansen looks like I had to change the hostname and add my domain to the hostname…

and it finally worked T_T that took hours thanks so much for keeping up on this thread