# Sorting and sending with postfix, fetchmail and courier-imap

## optilude

Hey!

After some advice from the rest of the forum, I'm trying to set up an IMAP server so that I can check my mail both from KMail and pine (and evolution and sylpheed or whatnot...). My setup so far is:

postfix for MDA. I've setup a virtual table for local delivery and set smtp relay to mail.gmx.net (my mail server). This works fine for local sendmail deliveries (i.e. typing root@localhost in To field sends to root.) It's using maildir's in ~/.maildir. 

fetchmail to get mail. I've set this up to check optilude@gmx.net (my email account) and deliver locally to optilude (my local user). This seems to work.

courier-imap for IMAP. This seems to work ok. I can access my mail in KMail through this, for example.

I'm having the following problems though:

1. I have three POP3 mail accounts I need to check regularly. I can set up fetchmail to poll all three, but then they all end up in the same IMAP INBOX folder. What I really want is to separate the three out (they're used for very differend purposes) into separe IMAP folders. I've created three folders (GMX, ITS and DCS, corresponding to the three accounts) under the IMAP inbox. However, I don't know how to sort incoming mail (probably based on the To header) into these folders.

2. Sending non-local mail is still a problem. All three accounts use SMTP, and I need to be able to send as all three. I tried following the Dial-Up section of the postfix FAQ, but I seem to have got it wrong, as when I send something, to a non-local domain (e.g. to myself as M.Aspeli@warwick.ac.uk - the ITS account), it's never delivered (or bounced, for that matter). I can create three identities in KMail and send directly to the SMTP servers like this - is this the best thing to do? 

3. I'd really like to keep track of my sent mail in an IMAP folder as well (perferably one for each account). Is this possible? Obviously, if I use direct SMTP in, say, KMail that'll end up in the KMail sent folder, but it won't show up in pine or any other client.

Thanks!

Martin

----------

## Microft

Hi!

I've a suggestion for just one of your problems. You can use imapfilter to filter the eMails of the three accounts after fetching.

Tim

----------

## compu-tom

#1:

procmail will do the filtering.

#2:

Which errors are reported? Get the mails rejected by your postfix or by the ISP's mail server? Do you use your postfix as relay?

#3:

Don't know KMail. Has it an Fcc: feature?

The mail is probably saved in the local folder "sent". Can you specify an Fcc: or "Save sent mails in ..." and select INBOX.sent?

----------

## optilude

 *compu-tom wrote:*   

> 
> 
> #1:
> 
> procmail will do the filtering.
> ...

 

Care to elaborate? procmail rather confuses me...  :Sad:  My maildirs are in ~/.maildir, and I've used maildirmake to create three sub-folders (which show up in KMail): GMX (for mail to @gmx.ne), ITS (for mail to @warwick.ac.uk) and DCS (for mail to @dcs.warwick.ac.uk).

 *compu-tom wrote:*   

> 
> 
> #2:
> 
> Which errors are reported? Get the mails rejected by your postfix or by the ISP's mail server? Do you use your postfix as relay?
> ...

 

Nothing. I probably set postfix up wrong. I send (through pine) and get no error message, no bounced message. 

 *comput-tom wrote:*   

> 
> 
> #3:
> 
> Don't know KMail. Has it an Fcc: feature?
> ...

 

Yeah, that sould work. Thanks a lot!

Martin

----------

## compu-tom

 *optilude wrote:*   

> Care to elaborate? procmail rather confuses me...  My maildirs are in ~/.maildir

 

Search the forum for "procmail and maildir". There are also examples.

 *Quote:*   

> Nothing. I probably set postfix up wrong. I send (through pine) and get no error message, no bounced message. 
> 
> 

 

I assume there are errors reported in a log file. What tells /var/log/mail.log (depending on your syslog configuration)? If the mails aren't bounced, do they remain in the mail queue?

```
mailq
```

----------

## optilude

Ah....

```

Feb  4 21:42:00 Jazzmaster postfix/smtp[15066]: 84B9483BAE: to=<csvni@warwick.ac.uk>, relay=mail.gmx.net[213.165.65.60], delay=4, status=bounced (host mail.gmx.net[213.165.65.60] said: 550 {mp001-rz3} Cannot resolve your domain - ungueltige

r Domain-Name in Adresse (in reply to MAIL FROM command))

Feb  4 21:42:01 Jazzmaster postfix/cleanup[15064]: 0C3D583C54: message-id=<20030204204201.0C3D583C54@localhost>

Feb  4 21:42:01 Jazzmaster postfix/qmgr[5900]: 0C3D583C54: from=<>, size=2249, nrcpt=1 (queue active)

Feb  4 21:42:02 Jazzmaster postfix/smtp[15066]: 0C3D583C54:to=<optilude@localdomain.localdomain>, relay=mail.gmx.net[213.165.64.20], delay=1, status=bounced (host mail.gmx.net[213.165.64.20] said: 553 {mp015-rz3} Only registrated user are allowed to use this system - Dieser Dienst ist eingetragenen Mitgliedern vorbehalten (in reply to MAIL FROM command))

```

So what? Normally I send through mail.gmx.net. My username is "optilude@gmx.net" (there's also a numeric equivalent I can't remember) and there's a password. Normally I don't use it though, but I think it needs pop-before-smtp for non-authenticated SMTP requests. How should I configure postfix?

Martin

----------

## compu-tom

 *Quote:*   

> Cannot resolve your domain - ungueltiger Domain-Name in Adresse

 

The From: header contains a domain name which is not resolvable. The cause for the rejection is to avoid spam and to ensure replies will reach you.

 *Quote:*   

> Only registrated user are allowed to use this system - Dieser Dienst ist eingetragenen Mitgliedern vorbehalten

 

Maybe the problem gets solved by solving the above (DNS). Otherwise first "fetchmail", then send mails.

----------

## optilude

About procmail:

I tried, really I did, but I still can't get it to work....  :Sad: 

This is my /etc/postfix/main.cf (sans comments):

```

queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = /usr/lib/postfix

mail_owner = postfix

myhostname = localhost

mydomain = localdomain

myorigin = gmx.net # This seems to be a problem 

inet_interfaces = all

virtual_alias_maps  = hash:/etc/postfix/virtual # maps local aliases

unknown_local_recipient_reject_code = 450

relayhost = mail.gmx.net # This seems to be another problem...

alias_maps = hash:/etc/mail/aliases

alias_database = hash:/etc/mail/aliases

home_mailbox = .maildir/

```

This works with ~/.fetchmailrc as:

```

# Configuration created Thu Jan 30 01:39:36 2003 by fetchmailconf

set postmaster "optilude"

set bouncemail

set no spambounce

set properties ""

set daemon 600

poll pop.gmx.net with proto POP3 tracepolls

       user 'optilude@gmx.net' there with password 'secret' is 'optilude@localhost' here options keep

```

Basically, I can now get mail sent to my GMX account, and it ends up in ~/.maildir. This is then read by courier-imap, which I can access fine from within kmaill.

Now, to add procmail to that equation, I've got a maildir folder GMX under my ~/.maildir (~/.maildir/.GMX). I added

```
mailbox_command = /usr/bin/procmail
```

to my /etc/postfix/main.cf and set a ~/.procmailrc as:

```

DEFAULT="$HOME/.maildir/"

MAILDIR="$HOME/.maildir/"

GMXDIR="$HOME/.maildir/.GMX/"

:0

* ^To:.*@gmx\.net

$GMXDIR

```

(That's not entirely what I want, 'cos I'd rather match on a tracepoll field than the To field (when I'm being BCC'd or CC'd), but I don't know how to do that.)

However, now I don't receive any mail at all. And I'm very lost!

Thanks for all your help so far!

Martin

----------

## compu-tom

 *Quote:*   

> myorigin = gmx.net # This seems to be a problem 

 

Mmh, in my main.cf is a similar line with my official domain.

 *Quote:*   

> * ^To:.*@gmx\.net

 

man procmailrc gives:

```
       If the regular expression contains `^TO_' it will be  sub

       stituted by `(^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-

       Envelope|Apparently(-Resent)?)-To):(.*[^-a-zA-Z0-9_.])?)',

       which should catch all destination specifications

       containing a specific address.
```

----------

## optilude

Well, ok, but I still can't fetch *any* mail and filter it with procmail. I'm sorry I'm so green with this, but could you please tell me step by step how to get fetchmail to download the mail, send it to postfix, which will then deliver it to my local ~/.maildir, and then get procmail to immediately filter that based on the TO_ field into the various subdirectories?

As I said, I can get the mail and put in my top-level inbox, but I receive no mail (or any warnings I can find) as soon as I put 

```
mailbox_command = /usr/bin/procmail
```

in my /etc/postfix/main.cf...

The procmail manpage says something about ~/.forward, which is entirely lost on me. Another thread mentioned the mailbox_command option, but as I said, when I do this, I stop receiving my mails and I have no idea where they go.

Regards,

Martin

----------

## optilude

Hey!

I've made some progess now... I can receive mail via fetchmail and sort it via procmail (there was a path inconsistensy in /etc/postfix/main.cf). 

However, I still can't figure out how to send things via sendmail through my ISP's mail relay (mail.gmx.net). I think I've followed the postfix FAQ to the letter, but my mail is still bouncing as above. Anyone else gotten this to work?

Martin

----------

## marder7

 *Quote:*   

> However, I still can't figure out how to send things via sendmail through my ISP's mail relay (mail.gmx.net).
> 
> 

 

Well I'm not familiar with postfix, procmail & co, but I know the policies of GMX: 

Using mail.gmx.net as your smtp relay only works when

1. sending mail with your GMX identity (the "from" header must be your GMX mail address), and

2. doing a pop-before-sending, because only pop has an authentication mechanism which lets you use mail.gmx.net as a smtp relay for a few minutes 

So I think you have to make sure in your sendmail config that every mail is sent as "optilude@gmx.net" (or whatever your gmx address is) and that a fetchmail-poll of your gmx account is triggered before the send command is invoked (also needs perhaps some delay)...

Hope this helps

Martin

----------

