How to configure postfix to not relay to local virtual domain?

9,883

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.

Share:
9,883

Related videos on Youtube

int 2Eh
Author by

int 2Eh

Updated on September 18, 2022

Comments

  • int 2Eh
    int 2Eh over 1 year

    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 [email protected] to [email protected] 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!

  • Chris
    Chris about 7 years
    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.
  • Peter Evans
    Peter Evans almost 7 years
    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.
  • Adonist
    Adonist almost 7 years
    That worked for me. It should definitely be considered as right answer.
  • Ray Oei
    Ray Oei over 6 years
    +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.
  • Admin
    Admin about 2 years
    Does not work for me. I`m trying to send email from mail2.domain.com to mail.domain.com. The user only exists in mail.domain.com and mail2.domain.com is not defined in DNS MX records.