# Easy way to put a mail into a maildir folder (dovecot)?

## Strunzdesign

Hi,

I successfully installed dovecot on my server to provide an IMAP-based storage folder. Until now, I'm using it just to archive all my mails here (I manually move them using my MUA, i.e., Kontact/KDE), so, until now, having dovecot for just IMAP access was sufficient.

Now, I'm looking for an easy method of injecting autogenerated emails into one of the maildir folders contolled by dovecot. These mails are generated by scripts, e.g., by using "mime-construct", in order to deliver notifications that a certain event happend. In my example, I have the VoIP PBX asterisk running on the same server and want an email to be created everytime someone talks on my phone box. My idea was to use "mime-constuct" and "nullmailer" to cooperate with dovecot, but I have no idea how to create an "easy" and "secure" setup involving as less components as possible.

My question:

Do I need a full-featured MTA such as postfix for it, or is there an easier method how to simply put a "hand-crafted" email into a well-defined maildir folder? The LMTP interface of dovecot looks promising, but as far as I understand the protocol of LMTP is does not use SMTP. I tested it using a TCP listener, as nullmailer is not able to access unix domain sockets, which are the default for dovecot and are considered the safest option to use LMTP.

I have no experience yet how to setup an MTA such as postfix, and it looks a bit overkill for my purpose. I just want to insert emails into my local storage folder... they are not designed to be sent somewhere. Any hint or advice is appreciated   :Cool: 

Thank you, kind regards,

Florian

----------

## cboldt

Use procmail to direct mail to various folders.  It has a bit of a learning curve, but once set-up, you can forget about it.

----------

## khayyam

 *cboldt wrote:*   

> Use procmail to direct mail to various folders.  It has a bit of a learning curve, but once set-up, you can forget about it.

 

cboldt, Strunzdesign ... an example of which was posted here in answer to a similar question recently.

best ... khay

----------

## Strunzdesign

Hi,

thank you both for your replies!  :Very Happy:  That thread khayyam referred to was new to me... seems that I missed it during my search. At first, I have to correct myself, I intended to write "procmail" in my question but somehow wrote "postfix".

As far as I understood how procmail works it is able to write directly to maildir-based folders, but that causes problems if those folders are managed by dovecot. In this case, dovecot would need some kind of a trigger that it updates its index. LMTP seems the way to go to keep the maildir folder under full control of dovecot.

Thus, I would try to setup the following setup:

a.) mime-construct -> nullmailer -> procmail -> dovecot via LMTP

or

b.) procmail with a handcrafted email via STDIN -> dovecot via LMTP

Method (b) seems to have a smaller footprint, so I'm going to start with that. Or did I miss something?

Regards,

Florian

----------

## cboldt

I run dovecot in mbox format, and it has no trouble keeping "up to date" with the mail strewing that procmail does.  The MTA in my case happens to be postfix.  The following chain just delivers the mail.  I have a typical SPAM folder, plus another ten or so for various separate interests.  A folder named "IN:system", for example, gets cronjob and system activity, and a folder named "IN:danfan" gets stuff from a particular listserv I subscribe to.

MTA -> procmail -> MailFolders

Separately from the mail delivery activity, dovecot serves the mail on demand.

From somewhere in the dovecot config ...

```
mail_location = mbox:~/mail/:INBOX=/var/spool/mail/%n
```

procmail strews to various folders in ~/mail, and admits some to /var/spool/mail/%n.

Procmail acts on mail sent to INBOX by MTA, diverting/strewing it as directed.  My mail reader is set to view the contents of ~/mail and INBOX, which is what dovecot is set to serve up when queried.

----------

## Etal

Why procmail? Its syntax is really obtuse and not fault-tolerant.

If you already have Dovecot, you can emerge it with the "sieve" flag, and use its LDA: http://wiki.dovecot.org/LDA

Then, just pipe the messages you want delivered through /usr/libexec/dovecot/deliver -k

You can then enable and set up the sieve plugin: http://wiki.dovecot.org/Pigeonhole/Sieve

It's a more painless to set up, and it works hand-in-hand with dovecot.

Personally, I have my mail set up like this:

```
IMAP/POP3 --> fetchmail --> dovecot-lda ---> ~/.Maildir <---> dovecot (IMAP) <--mbsync--> remote maildirs

                              ^                   ^                      ^

                              |                   |                      |

/sbin/sendmail (OpenSMTP) ----'                   v                      `---> IMAP Clients

                                                 Mutt
```

(fetchmail mainly because it supports listening for IMAP IDLE and retrieve mail in real time)

----------

## cboldt

I like the dovecot-sieve suggestion.  Thanks for the pointer.  I never used that, have a fairly complex set of procmail recipes here so stick with that, inertia and all.

----------

## Etal

You can always migrate incrementally, by setting the last procmail rule to pipe to LDA (That's what I did  :Smile: )

----------

