Fetch new Mails (Also from Subfolders) from another IMAP server as new Mail in Postfix

emailpostfix

everyone. I have installed Postfix on a server with Aliases and Domains from a MySQL Database.

It is configured to forward some adresses to other Mail Accounts and also delivers some mails in local mailboxes that will be queried over a dovecot imap server.

For this example let there be two users:

  • forwarded@domain.com what is a user that gets its mail just forwarded to let's say forwarded@forwarded-host.com
  • local@domain.com what is a user that accesses its mail from local IMAP.

Now, I want to fetch some Mails from another mailserver and handle them as if they were sent to a user of my Mailserver.

Lets say those corelations exist:

  • forwarded@domain.com has two external accounts: user-a@externaldomain.com and user-a@some-other-company.com
  • local@domain.com has also one external account user-b@externaldomain.com

The Problem is the new mails on that other Mailserver is not always in the inbox, it might be in subdirectories: mailinglists/all or mailinglists/it but also in mailinglists/some-other-department which is not interesting and should not be delivered.

I already found a programm called fetchmail but I cannot find how to fetch subdirectories or decide which subdirectories are fetched.

Best Answer

You can use the folder option. Just put it in the fetchmail config file (Default is .fetchmailrc).

poll mail.server.com protocol IMAP
    user 'xxx@xxx,com'
    password 'xxxxxx'
    folder 'mailinglist'

See man page or search for "fetchmail folder option" if you need more examples.

Related Topic