Setting up Mail Forwarding in Postfix

To setup mail forward in postfix,

Edit postfix config file

Add

Create file /etc/postfix/virtual_alias_domains

Add your domains on this file. 1 Per line.

Example

Here i have 2 domains added, postfix will service as incoming email server for these 2 domains.

Now create /etc/postfix/virtual_alias_maps, this file will list all email accounts you need and where the email needed to be forwarded to.

Add

here email coming to [email protected] and [email protected] get forwarded to [email protected]

If you need catch all email account, just use

If you want email forwarded to more than one recipient, add them one after other like

Now run

Restart postfix

You need to set MX record of your domain to point to server running the postfix mail server to receive mails.

Configure Postfix to sent emails using MailGun

First install requirements

Run

Edit /etc/postfix/main.cf

Add

Create file /etc/postfix/sasl_passwd

Replace SMTP_LOGIN and SMTP_PASSWORD with your user and password you get from mailgun.

Run

Restart postfix

You can test email with

eximrm

Here is a bash script to delete mails in exim mail queue. Helpful when you have lot of spam mails in mail queue.

Create file

Add

Make it executable

Monitor Server Mail Queue

Run following script every 1 hour to monitor/alert email queue

SASL authentication no mechanism available

When sending email from postfix mail sever that use mailgun for relaying mails, i get error

Jan 4 03:16:06 serverok-vm postfix/qmgr[22652]: 795731A8D: from=, size=820, nrcpt=1 (queue active)
Jan 4 03:16:06 serverok-vm postfix/smtp[24050]: warning: SASL authentication failure: No worthy mechs found
Jan 4 03:16:06 serverok-vm postfix/smtp[24050]: 795731A8D: SASL authentication failed; cannot authenticate to server smtp.mailgun.org[34.237.7.101]: no mechanism available
Jan 4 03:16:06 serverok-vm postfix/smtp[24050]: warning: SASL authentication failure: No worthy mechs found
Jan 4 03:16:06 serverok-vm postfix/smtp[24050]: 795731A8D: SASL authentication failed; cannot authenticate to server smtp.mailgun.org[34.232.180.42]: no mechanism available
Jan 4 03:16:06 serverok-vm postfix/smtp[24050]: warning: SASL authentication failure: No worthy mechs found

On checking postfix mail queue, the mail is stuck in queue

The problem is fixed by installing libsasl2-modules.

On Debian/Ubuntu

On RHEL/CentOS

Now restart postfix.

Transnational Email Providers

Amazon Simple Email Service

$0.10 per 1,000 emails sent. 65K free emails per month if you are hosted on EC2.

Disadvantage: You can only sent from @your-domain.extn, if you have a SAS application and need to sent from some other email address, you need domain added to SES and verified.

https://aws.amazon.com/ses/pricing/

ElasticEmail

Free plan allows you to send 150K emails per month.

Disadvantage: All outgoing email must include physical address.

https://elasticemail.com

MailGun

First 10K emails for Free every month. Pay as you go pricing. After 10K free email, you will be charged $0.00050 per email.

https://www.mailgun.com

MailJet

Free account allow you to send 6,000/- email per month. Monthly plan start at $7.49 per month for 30k emails.

https://www.mailjet.com

SparkPost

50K Emails for $9 per month. If you are on AWS, you can get it cheaper from marketplace.

https://www.sparkpost.com

SendGrid

40K email per month for $9.95 per month.

https://sendgrid.com