In this quick tutorial we will see how you can enable outgoing emails through mail gun relay host. This will be useful if you are using self hosted email with shared IP address. Because when you directly send email from your SMTP server it may be rejected by many major email service providers if you don’t have a static IP entry mapping to your domain. So for outgoing email you can configure the relay host through other email service providers. In this example I am using Mailgun but you can use any provider.
First create an email account using your iRedmail admin page for the new domain.
Add the domain name in mailgun for outgoing email.
After this create SMTP credentials in mail gun and the entry in the /etc/postfix/sasl_password
Entry needs to be in following format as shown below.
@domainname smtp-username:smtp-password
After adding the entry use postfix function to compile the file as .db file using below command.
postmap /etc/postfix/sasl_passwd
After this add the SMTP relay host in the database by following below steps. Switch to postgres user.
su - postgres
psql
\c vmail
SELECT * FROM sender_relayhost;
insert into sender_relayhost(account,relayhost) values('@your-domain.com','[smtp.eu.mailgun.org]:587');