# QMAIL IS DRIVING ME GOING NUTS

## OmniVector

Ok. i have successfully setup a dns and apache server. that was fine.

now i'm trying to get something as simple as email tristan@otierney.net to go to a mailbox that i can check from evolution.

here are the programs i *know* of:

qmail

qmail-pop3d

courier-imap

vpopmail

horde/imp

i don't know the first thing about getting these to all play together. i've read man pages, tutorials, and forum posts for hours and gotten absolutely nowhere. how in gods name do i setup email?!!?

i'm running a virtual domain server with about 10 domains, so that's why vpopmail is in the list. i want to support imap and pop3, that's why courier-imap is in the list.  i can't find any good tutorials anywhere online on how to set these all up properly in linux, let alone gentoo.

if anyone can at least give me some links to start me out (and i don't mean the homepage for qmail and vpopmail because those didn't help one bit).

mind you i also have mysql in my use flags, with aworking mysql server.

thanks if anyone knows what i'm going through and can help

----------

## idl

ok.. first of all you need a smtp server, sendmail, postfix etc.. you then need a pop3 and/or  imap server so that you can check your mail.

Say you setup postfix you then create a normal user on the server, all mail then sent to <user>@whatever.com will goto thier mailbox, you then use a mail client to login via pop3 or imap to receive these emails.

good luck, its not as hard as it may sound  :Smile: 

----------

## OmniVector

ok lets start off with the SMTP server, qmail. (i'm more inclined to use qmail based on the security track record of it).

lets say i emerge qmail, then what?  how do i know it's working, and configured properly.

----------

## kerframil

Are you sure you read all the guides? I know it can be hard filling in some of the gaps, but certainly qmail has pretty good documentation from various sources. Anyway, here's a quick-start guide (tip: Webmin's very nice Qmail module makes a lot of this really easy, except for the first few things):

Create maildirs for your users:

```
maildirmake /home/user/.maildir

chown -R user:user /home/user/.maildir
```

Repeat for each user.  FYI, permissions for ".maildir" and sub-items should be 700. maildirmake will set those permissions properly, but will set ownership according to the user who ran maildirmake. That's why I've put the chown command in there.

Check your /etc/tcp.smtp. Here's mine (I had to add the option for my 10.0.0.0 subnetted LAN, otherwise your local clients won't be able to send mail to anybody other than local users):

```
10.0.0.:allow,RELAYCLIENT=""

127.0.0.1:allow,RELAYCLIENT=""

:allow
```

You need to compile that into a rules database like so:

```
cd /etc

tcprules tcp.smtp.cdb tcp.smtp.temp < tcp.smtp
```

Setup an alias for at least the root user. Aliases are entered as individual files under /var/qmail/alias. To enter an alias for root, create a file called /var/qmail/alias/.qmail-root - here's mine:

```
&kerin@recruit2recruit.net
```

Note that the address is entered with an ampersand in front. If in doubt, just use Webmin.

Set your default domain (the domain that gets appended to an email alias, if you mail client doesn't specify a fully qualified email address) in /var/qmail/control/defaultdomain. This should just contain a single line with your chosen domain name.

Tell your mailserver which domains it should accept mail for. You can specify as many as you like in the form of domains entered as single lines in /var/qmail/control/rcpthosts and /var/qmail/control/locals. Yes, there's a difference between the two files but I haven't worked out what yet, so I've made them the same and it works. Obviously, you'll want otierney.net to be in there.

You can tell your mailserver which FQHN (hostname) it uses to identify itself to a client that connects in /var/qmail/control/me. Useful if you don't want your mailserver to identify itself using your normal hostname. If you have an MX record defined in your domain so that mail is delivered directly to you from other hosts on the Net then you should make sure qmail identifies itself with the same hostname you specified in your MX record, otherwise you might get blacklisted or experience other issues with strict foreign mailservers.

You can ban domains and addresses in /var/qmail/control/badmailfrom. This is also useful if you don't want a mailbox alias to be able to have mail delivered to it via all domains your mailserver supports.

Ah, and every user will need to have a .qmail file in their home directory which explains how mail is delivered. Here's the simplest configuration:

```
./.maildir
```

which just means to place the mail in the maildir which is called ".maildir" which exists in the current directory. If you use procmail then you could insert this line in .qmail instead:

```
|preline /usr/bin/procmail ~/.procmailrc || exit 111
```

If you decide to use procmail, then users will need .procmailrc files in their directories too. I'm not going to go into that, but I will say not to use the file locking feature of the procmail syntax because it's not needed with the maildir format.

That just scratches the surface, but I think that should be enough for basic functionality. Just fire up qmail with:/etc/init.d/svscan start and send a mail with SMTP (use telnet on port 25 if you have nothing else to hand). Assuming you sent it to "user", the mail item should be under /home/user/.maildir/cur, and you should be able to view it in a text editor. Qmail will allow mail to be sent to valid users on your system, unless you put them in badmailfrom. Simple.

Now you'll want to emerge courier-imap to provide access to those maildirs ( so you can do your evolution test  :Smile:  ).

----------

## OmniVector

before i get into all that .  i changed the maildir from .maildir to Maildir (something to do with vpopmail or courier-imap's preferences?)

it's easy to update /etc/skel and the current root mail account for that.

that's a good starting point as well.. how do i send an email through telnet as you speak? i haven't done it before.

i'm fairly sure i have the tcp rules setup already (part of the qmail ebuild)

and i already have an alias for root and postmaster created.

and why procmail? (is there some advantage to it)

----------

## kerframil

 *OmniVector wrote:*   

> before i get into all that .  i changed the maildir from .maildir to Maildir (something to do with vpopmail or courier-imap's preferences?)

 

Fine, you can call it what you like. The argument against not using a dotfile is that people who have access to their home directories can more easily see the folder and manipulate it which isn't always desirable.

 *Quote:*   

> how do i send an email through telnet as you speak? i haven't done it before.

 http://www.daemonnews.org/199905/telnet.html

 *Quote:*   

> and why procmail? (is there some advantage to it)

 

It can apply sophisticated filtering and distribution rules to all locally dropped mail. I use it to filter my incoming messages into different maildir folders at the time of arrival but it can do a whole lot more than that such as filtering spam or routing messages though external programs (virus checkers and the like). In fact qmail can do that sort of routing too (the |preline command I showed you pipes the message through an external program so you can imagine the possibilities). Some alternatives to procmail are maildrop and Mail::Audit. Just don't get the roles of the two components confused. qmail is a MTA (mail transaction agent) and procmail is an optional LDA (local delivery agent). Of course qmail can be an LDA on its own but if you want more sophistication you use things like procmail.

----------

## OmniVector

ok *jumps with joy* the telnet test worked

i was able to relay email and send mail locally (as well the email appeared in the correct email box as it should have)

now how do i get evolution to receive it through IMAP and POP (i'm trying to support both services).

emerge courier-imap yes?

***EDIT***

before i jump too far ahead, i want to use vpopmail to manage my virtual domains (or so i hear it's good for that).  i have about 10 webpages hosted on my machine.  and i don't want tristan@halo43.com to require the useraccount tristan. instead i want it to be independent of my linux user accounts.

I already have mysql installed and configured.

do i have to setup vpopmail first?  i edited the courier-imap ebuild to compile with the optin --with-authvpchk or something like that to enable vpopmail integration. (but i haven't emerged it yet)

----------

## kerframil

OK, good.

But my knowledge starts to get a bit thin at this point because I've never done virtual hosting with this stuff. What I do know is that qmail can create "virtual" mailboxes which do not have to have anything to do with a real user account.

I also found this site dedicated to qmail + mysql which might prove helpful:

http://iain.cx/unix/qmail/config.php

The good news is that the relevant patch is already included in Gentoo's qmail ebuild.

Courier-IMAP will certainly give you access to the maildirs over IMAP (and POP3) and supports a slew of authentication options. Courier runs a separate authentication daemon as well as an IMAP daemon. The important file is /etc/courier-imap/authdaemonrc. This excerpt from mine gives you an idea of what can be done:

```
#authmodulelist="authcustom authcram authuserdb authldap authmysql authpam"

authmodulelist="authpam"
```

and here's a page about the authentication mechanisms in courier-imap: http://www.inter7.com/courierimap/INSTALL.html#authmods.

As for vpopmail, I have no experience of it I'm afraid. Nor have I of this, but I just thought I'd point it out because it might be relevant to you: net-mail/qmail-vmailmgr.

If you make any progress with this stuff, please let me know because I'd like to cover it in an epic (and constantly delayed) server guide I'm working on.

----------

## OmniVector

ok now we're getting somewhere

email sent to otierney@otierney.net is working.

but i can only check it through pop. imap isn't receiving it for some reason.

i have yet to attempt getting vpopmail working.

here was a large portion of my problem: everything expected the folders to be .maildir, not Maildir.  for some reason courier hated Maildir (even though thats how i had it in my settings)  whatever.. now it's .maildir.

now i'm trying to solve a couple more issues. right now otierney@otierney.net only works because the machine i'm running has a linux (/etc/passwd) account named otierney. i'm hoping to change this to a virtual account (such as tristan@otierney.net) that i can check with a different username/password.   imap working would be nice but i'm just glad anything works.

i looked a bit into qmail-vmailmgr but i saw that vpopmail was very similar and more full featured.

----------

## kerframil

Let's leave the virtual and SQL stuff aside for a moment.

 *Quote:*   

> imap isn't receiving it for some reason.

 

Minor carp: IMAP doesn't receive anything. So I don't follow, can you be more specific? I presume you've setup your authdaemonrc and imapd files in /etc/courier-imap (set authentication type to PAM as I did for now) and started the /etc/courier-imapd service. I also presume you've connected (or tried to) with an IMAP capable email client. So what gives? Have you tailed your /var/log/everything/current to see what's happening? Here's an example log of a successful session:

```
Dec 27 02:19:50 [imapd] Connection, ip=[127.0.0.1]

Dec 27 02:19:50 [imapd] LOGIN, user=foo, ip=[127.0.0.1]

Dec 27 02:19:51 [imapd] LOGOUT, user=foo, ip=[127.0.0.1], headers=0, body=1520

Dec 27 02:21:11 [su(pam_unix)] session opened for user root by foo (uid=500)
```

Are your POP3 connections made through courier-pop3d? If so, then you've got authentication nailed for the moment.

 *Quote:*   

> i'm hoping to change this to a virtual account (such as tristan@otierney.net) that i can check with a different username/password.

 

In qmail, the answer is MUA (mail user assignments). You can point to an arbitrary directory which must contain a .qmail file to say where to deliver, which can also be arbitrary. See section 3.6 here: http://www.lifewithqmail.org/lwq.html#virtual-domains. Or use the control panel in Webmin and see how it changes the configuration files for qmail. It shouldn't be hard to get that working.

I think you should be getting close after that. I've already given you a link giving you the lowdown on qmail and mysql. Then you'll need to change courier-imap to use "authmysql" in authdaemonrc then have a look at /etc/courier-imap/authmysqlrc.dist. Read through that file - it's pretty self-explanatory. The good news is that you can define a field in the table which will tell courier-imap where to look for the maildir for any of your SQL defined user accounts). And the file allows you to completely customise the table names and field names it looks for so I guess you should ensure it matches the schema that qmail uses which I doubt will be too hard.

Anyway, I should get courier-imap working as it stands now before proceeding with that stuff.

----------

## OmniVector

here's an example:

when i setup the account otierney@otierney.net in evolution as a pop server, it receives the email in my inbox.

if i set it up with imap, it succees (i see no errors about the password being wrong) but the email never appears.

i checked my /var/log/everything/current file and see nothing indicating a connection for imap. all i see are some errors about authentication failing but those are my fault (i was fooling with the config)

i'll jump into the mysql stuff as soon as imap works heh  :Smile: 

----------

## kerframil

Some thoughts ...

It's not because you downloaded the mail with POP3 (which will remove it from the server) therefore meaning that there was no mail left for IMAP to see?

And you have MAILDIR=.maildir in imapd? When you create the IMAP connection in Evolution does the correct folder heirarchy appear (you may have to subscribe to the folders)? And you're not looking in your local Inbox rather than the server-side one in Evolution? POP3 will pull the mail from the serve and store it client-side under "Local Folders". IMAP is quite different - it operates on the server, leaving the mail there by default and the set of folders are different - the default Inbox in Evolution is not the correct place to be looking. Pin open the full folder list and make sure you're looking at the Inbox folder under the node equivalent to the friendly name you gave your IMAP mail account, not the Inbox under "Local Folders".

If you continue to have problems we can compare config files if you like.

PS: The lack of relevant lines in the log might be because you're using metalog and the buffers haven't been flushed. Send metalog a -USR1 signal to make it report things realtime.

----------

## OmniVector

 *Quote:*   

> 
> 
> It's not because you downloaded the mail with POP3 (which will remove it from the server) therefore meaning that there was no mail left for IMAP to see?
> 
> 

 

definatly not.. i'm not *that* newbie  :Razz: 

 *Quote:*   

> 
> 
> And you have MAILDIR=.maildir in imapd
> 
> 

 

i originally thought that was the problem, but to make sure i cleared out all my configs for courier and re-emerged it, and it's definatly .maildir

to make sure i wasn't having config problems i also rebooted to clear any caches or current running courier processes

 *Quote:*   

> When you create the IMAP connection in Evolution does the correct folder heirarchy appear (you may have to subscribe to the folders)

 

that's another problem. i have another IMAP account, and it gets a folder by itself like you describe.. however i can't seem to get a folder when i use my email server.

 *Quote:*   

> PS: The lack of relevant lines in the log might be because you're using metalog and the buffers haven't been flushed. Send metalog a -USR1 signal to make it report things realtime.

 

doh i am using metalog, i forgot about that buffer system i uses

----------

