Question

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

  • Posted July 14, 2016
  • Email

Hi, 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/main.cf

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

Subscribe
Share

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

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.

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.

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/main.cf 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 main.cf, and add your domains:

example.com   #domain
example2.com   #domain
Test1.com #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: http://www.postfix.org/VIRTUAL_README.html