0

I have an application that needs to write emails directly to local imap accounts. No MTA (Postfix,Sendmail etc.) in between so as to keep it simple to maintain, and no MTA vulnerability to worry about ,since there will be around 100K IMAP accounts (maildir files).

Is it possible to write directly to a Maildir file programatically without taking the help of an MTA?

So far, I have looked at femtomail but it's too simple for my needs since it's intended for use on a single-user machine.Also saw some python modules which would do this but not sure if Python would be fast enough considering we are talking about 100K IMAP accounts here.

Planning to do this on an AWS or a DO instance. Any suggestions on the architecture also will be much appreciated.

Sharjeel
  • 290
  • 1
  • 7
  • 17

1 Answers1

1

Most IMAP servers are nicely modular and include a delivery agent, and/or cooperatively use a standard folder format for which such a tool already exists. There is no requirement to invoke an MTA for anything in this scenario, and this is arguably a conscious design decision (also makes system testing of the IMAP server etc a lot simpler!)

The Python mailbox library supports writing to and otherwise manipulating maildir folders.

# Untested, based on example in documentation
import mailbox
destination = mailbox.Maildir('/path/to/folder')
destination.add(message)

I seriously doubt this code is going to be CPU-bound anyway (writing to disk will tend to be the bottleneck) so the speed of the language is probably not going to be a concern (and I have not found Python to be too slow for user-space stuff, generally).

Since you tagged this Procmail, the Procmail way to do this (which is however probably overkill if genuinely all you need to do is write to a maildir folder):

:0
/path/to/folder/

where the trailing slash is significant (leaving it out selects a different delivery format -- Berkeley if folder is a plain file, Procmail's own directory-based format if it's a directory).

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 1
    If you seriously run out of CPU, forking [femtomail.c](https://git.lekensteyn.nl/femtomail/tree/femtomail.c) to remove the addition of a `Received:` header and replacing the silly default options with a maildir folder path would seem like an easy exercise, even if you are not a C programmer. – tripleee Mar 06 '17 at 05:56