Setting up SMTP on top of Postfix for 2 websites on the same server

Posted July 14, 2016 7.4k views

I have a website running on a droplet on DO (ubuntu). I’d like to implement virtual hosts, and setup another website on the same droplet.

So i wondered how can i set the SMTP credentials for this new website. Currently, i have my sendgrid credentials in /etc/postfix/sasl_passwd , and configured in /etc/postfix/

But those are for just one account. Is there a way that i can use another SMTP account for the second website? Or create a sub-account so the transactional emails can go through for the 2nd website?

Any help is appreciated, thanks

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
2 answers

You can configure Postfix for multiple domains by using a hash file, which contains the list of domains used for local delivery. Look at the file /etc/postfix/ for this section:

# Define the domain list as hash file or as list in the config file.
virtual_alias_domains = hash:/etc/postfix/virtual_domains

Then, create the file you specified in the, and add your domains:   #domain   #domain #domain

Save the file, then run this command to create your hash db file:

postmap /etc/postfix/virtual_domains

Finally, reload Postfix:
/etc/init.d/postfix reload

The Postfix documentation may help you further if you want to make a more complex setup:

Can you provide a bit more information on your use-case? It is possible to use domain mapping to handle email for multiple domains in postfix and this guide will help you in setting that up. SASL will then let you configure authentication.

What I am confused by is your reference to SendGrid. Are you relaying emails from postfix via sendgrid rather than sending them directly? Is this being used to send emails from a web site or script or do you have users who will connect via SMTP directly? I think by better understanding your intended use case I can help you to find a good solution.

  • hi @ryanpq , yes i should explain better.
    I have setup postfix on my ubuntu 14.04, and then i am using an external SMTP on top of it for the sake of better delivery. I followed this guide by linode - .. and i use SendGrid.

    Now, that works awesome. Now, i want to start another website on the same droplet (virtual hosts). But Since my postfix is configured to use sendfix on a specific domain, i’m confused how can i set things up for the other domain.

    Please tell me if there is something i missed in explaining, and i appreciate your help.