I have set up a SMTP server with iRedMail on Ubuntu 14.04 LTS and everything is working smoothly. I can create new users and send e-mails.

My situation however is a bit more complicated: I need this server to send e-mails on behalf of my domain name "sampledomain.xxx" but I'm using a hosted mail service to receive e-mails. My domain DNS's MX records are set to a different IP than the SMTP server I've just set up. Basically this should be an outgoing-only SMTP server.

The problem arises when I need to use the SMTP server as user1@sampledomain.xxx to user2@sampledomain.xxx because Postfix thinks that mail should be relayed internally, but it doesn't find the address in the virtual domain's mailboxes and thus fail to send the e-mail.

How can I configure Postfix to not relay internally such e-mails and instead resolve MX records and send them as classic e-mails?

Many thanks!

2 Answers 2


Open your postfix configuration file (usually /etc/postfix/main.cf) in a text editor. I like vim.

$ sudo vim /etc/postfix/main.cf

Find the line where mydestination is set. It probably looks something like this:

mydestination = $myhostname, localhost.$mydomain, localhost

Comment that line out by prefixing it with a #.

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

Add the following line and then save the file.

mydestination =

Restart postfix

$ service postfix stop
$ service postfix start

Postfix will no longer try to deliver 'local' email to this server but will use the SMTP server given by the DNS MX record.

  • Not sure why this isn't an accepted answer, less still why it was downvoted - worked for me, except I just had to remove just one domain from the list rather than the whole list.
    – Chris
    May 17, 2017 at 10:07
  • Thanks, Chris, I'm glad it worked for you. I've never understood down votes without explanation. Some people just don't seem to get it. May 23, 2017 at 14:54
  • That worked for me. It should definitely be considered as right answer.
    – Adonist
    Aug 3, 2017 at 15:41
  • +1 from me ;-) Only needed to remove the $myhostname from the string, but I suppose technically commenting the whole line should be fine as there are no local mailboxes.
    – Ray Oei
    Jan 4, 2018 at 21:27

You may want to exclude only $mydomain from mydestination list, i.e:
mydestination = $myhostname, localhost.$mydomain
in case your hostname was .sampledomain.xxx This setup would still allow receive local system notifications, such as root

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.