Question

How to create domain forwarder for non existing emails?

Hello,

How to create domain forwarders for non existing emails on my virtual server?

I have postfix installed and configured. On top of my configuration file in /etc/postfix/main.cf I have:

email@domain.com existing@gmail.com email1@domain.com existing@gmail.com email2@domain.com existing@gmail.com

In my domain zone I have Gmail MX records automatically set, but I don’t know what I miss or doing wrong. Any help?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hey,

Finally I sorted it you!

To create the sub-domain “mail.domain.com” in your domain zone you need to add “mail” instead of the full sub-domain name and your droplet IP. When I did these changes the sub-domain start propagating and I was able to point the forwarder.

You will also need to unblock port 25 (SMTP) or to use alternative port like 2525 for the connection:

$ firewall-cmd --zone=public --add-port=25/tcp or $ firewall-cmd --zone=public --add-port=2525/tcp

Then reload the firewall:

$ firewall-cmd --reload

Test if the port work with telnet from your local computer terminal:

$ telnet domain.com 25

The result must look like mine below:

Trying Dropplet IP… Connected to domain.com. Escape character is ‘^]’. 220 domain.com ESMTP Postfix

If the allowed ports work you can add them permanently with:

$ firewall-cmd --zone=public --permanent --add-port=25/tcp or $ firewall-cmd --zone=public --permanent --add-port=2525/tcp

The again reload the firewall:

$ firewall-cmd --reload

Once these changes are done the forwarder will start working.

In my /etc/postfix/main.cf I added the lines below at the end of the file:

myhostname = domain.com inet_interfaces = $myhostname, localhost virtual_alias_domains = domain.com virtual_alias_maps = hash:/etc/postfix/virtual mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128

The final step was to include the forwarders in /etc/postfix/virtual somewhere at the end of the file:

email1@domain.com me@gmail.com email2@domain.com me@gmail.com

When the changes are done restart postfix and your forwarders will start working as soon your mail.domain.com is fully propagated usually shortly in about 10 minutes.

Hi Ryan,

Thanks for the reply.

I will test what you suggest and write back here.

If your domain has gmail MX records on it than emails sent to your domain would be sent to gmail’s server (which would reject them if you dont have “Gmail for your domain” services).

You’ll need to create MX records that point to your droplet. First create an A record for mail.yourdomain.com and point it to your droplet, next create the MX records for mail.yourdomain.com

If these changes once applied don’t resolve the problem I would recommend sharing your full postfix configuration here and also checking the error logs in /var/log/ for any indications of a problem.

Running mail services can be a headache and if you only need a limited number of boxes or just want to forward to your gmail account you may want to look at zoho.com which provides a free service for up to 20 (i believe) mail boxes for your domain. I use them for a couple of my own projects.