Take all email sent to a domain, and filter it into folders based on the alias

0

I have an email domain name.sld.tld, that I wish to catch most (excl admin, webmaster, and other spam targets) emails sent to *@name.sld.tld and either:

  • Forward them to another email account running in Gmail such that the address is rewritten from alias@name.sld.tld to accountname+alias@gmail.com
  • OR automatically filter the emails based on the incoming alias into a folder/label of the corresponding alias, creating one if it doesn't already exist. ie, no intermediary forward (preferred option)

Why? Something akin to what @SwiftOnSecurity tweets about here. I've tried tweeting them how they do it, but got no response:

I figure I probably need to write something myself to do it, but if @SwiftOnSecurity is doing it, there has to be a simple way OOTB from something, right?

It seems like its the email equivalent to mod_rewrite that I wish to achieve.

Ashley

Posted 2015-03-04T23:42:12.683

Reputation: 397

What email server are you using? – music2myear – 2017-04-04T22:29:39.047

@music2myear see my answer below: https://superuser.com/a/950035/91570

– Ashley – 2017-04-09T17:29:03.613

Answers

2

There is a solution that seems tu do exactly whjat you want: the cyrus IMAP server together with its sieve implementation.

Sieve basically is a server-sided domain-specific scripting language, that allows you to create elaborate rules for finding a target folder for an email. Its intended use is to auto-sort e.g. mailing list mails into their respective IMAP folders, but since any header can be used as a criterion, you can also use the receiver.

A complete setup would consist of

  • a cyrus IMAP server
  • an MTA configured to accept (nearly) all mail for a domain and deliver it to the same IMAP mailbox
  • DNS setup to make this MTA the responsible MX for the domain
  • your choice of sieve scripts to sort the mails into the folders

I have been using such a system to auto-sort many of my mails for years.

Eugen Rieck

Posted 2015-03-04T23:42:12.683

Reputation: 15 128

Hrmm this is definitely what I'd like to be able to do, but I don't wish to run my own email server... if only I could use sieve scripts with Gmail or Office 365 and I'd have my solution! Do you know if you can wire up a sieve implementation with GMail's IMAP endpoint? – Ashley – 2015-03-05T17:41:05.407

Sieve comes when mail is delivered to an IMAP server, not when it is read from it. So GMail's IMAP endpoint is of no use - it goes to the wrong side of the process. – Eugen Rieck – 2015-03-05T23:42:36.160

https://www.fastmail.com/ seems to support Sieve out of the box, and has a very Gmail-esque interface. They're also an Australian company, despite servers being hosted in the US, hopefully means they're a bit more protected from NSA interception (but really, email isn't a good way to think you're secure) – Ashley – 2015-03-06T14:23:40.110

I have ended up signing up for fastmail.com they suit my need perfectly. I can create folders in the web interface, and immediately start having email received into them using their dot and plus addressing mechanism. Also useful to understand is their mail flow/email delivery.

– Ashley – 2015-08-03T16:47:50.003

1

I have ended up signing up for fastmail.com as they suit my need perfectly. I can create folders in the web interface, and immediately start having email received into them using their dot and plus addressing mechanism. Also useful to understand is their mail flow/email delivery.

For example: with the right folder hierarchy already created, emails sent to address beta.gamma@alpha.example.com would automatically be delivered to INBOX\Alpha\Beta\Gamma without any manual rules needing to be configured. The only downside is that you can't have folders automatically generated based on incoming emails, but imagine that's to prevent abuse.

The way I'm using this is such that I can set up category folders, such as social or payments and then can refer to them with service-specific email addresses: facebook@social.example.com, paypal@payments.example.com.

Fastmail uses Sieve, Cyrus and some custom development in the background, hence leaving the original answer as chosen

Ashley

Posted 2015-03-04T23:42:12.683

Reputation: 397

Hey. Would you mind sharing what your Sieve config looks like for the hierarchy sorting? – Xælias – 2018-01-15T00:26:13.457

@Xælias unfortunately that's all handled by Fastmail; I don't have a Sieve config it just does it for me built-in to the product. They're fairly receptive, so they might give that information if you ask? – Ashley – 2018-01-15T15:42:27.300