Using Postfix mail relay through Mailgun/Sendgrid/etc.


I've been really struggling with email server hosting for a while now, as I had some issues with users getting exploited and/or my mis-config of Postfix that apparently allowed open relays for a while, etc., etc... I basically had given up completely on wanting to host email in any way. However, now I'm really annoyed with all the hoops to go through to get my clients onto 3rd party email solutions, so I'm back to the start again trying to solve this stuff to help them on my servers again.

A new server of mine is now set up on Google Compute Engine, so I'm looking into maybe using Mailgun for outgoing (and possibly incoming) email, as per some work I did recently on another GCE project where we used Mailgun. I'm not hugely familiar with GCE, but I know outgoing email is an "issue", to be brief on that.


So.. I'm considering Mailgun with Postfix on my Virtualmin server (maybe going to shift all my email hosting to go through relays, if this works.)

First trouble with this is just to be sure I'm setting things up correctly, I don't think there's a current "Mail Relay" plugin for Virtualmin/Webmin anymore? Following this:,mail_relaying_with_virtualmin

Since I don't see a plugin that's newer than 2008 (at, I am now wondering if it's enough to simply setting up the "Send outgoing mail via host" setting to use the Mailgun (or other) SMTP server and credentials provided from Mailgun in the Postfix setting here: Webmin > Servers > Postfix Mail Server > SMTP Authentication And Encryption

(Incoming email through a relay is a whole other subject at this point, so I'll settle for outgoing through Mailgun and incoming direct to Postfix.. hope to solve them both ultimately.)

The only other option I see is to go directly into editing the /etc/postfix/ file as described here (again, instructions for Mailgun):

...phew! Lot of info and maybe too much detail, but i'm trying to both be sure I don't overlook anything, as well as provide info for future searchers.

Please advise on the best way to set up this email relaying thing so I can stop being an email server admin -- or tell me if I'm going at this all wrong? Thanks for any help setting this up well.



Howdy -- yeah those Mailgun instructions for setting up email relaying are what I would try. Those would allow you to setup a username and password for relaying email through a remote service.

Thanks. I tried a couple more things but maybe have to set this aside due to time constraints. I hate email so much, but can't seem to sort out a good way to handle it. Might have to wait for another day.

FYI, I got this reply from Rackspace (Mailgun guys) when asking about some of this:

To automate domain creation, you could make a request to our Domain API : Then, you could setup Postfix with Sender Dependent Authentication. Here's two references for the setup :

Oh man, I got this all working (well, on a limited scale of one server and 2 domains for now)!

I'll see if I can write up my results here for others to read later, but I'm swamped right now and have to get back to work. It turns out I had one little misconfiguration, but also I had missed another step I needed after that. A situation where two bits of info were spread across a couple resources, so I had to pull them together.

Anyway, the 2nd link above ( is great for how to get multiple domains working through Postfix/Mailgun. Good stuff, for anyone reading before I get something written up.

I'll try to get something written up soon, in case it helps. Thanks for the help.