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

July 14, 2016 364 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

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.

Have another answer? Share your knowledge.