The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

Help with my mail server

Locust76Locust76 Registered User regular
edited February 2011 in Help / Advice Forum
Hello,

So I just got a mail server up and running. It's a server running Debian, Postfix, Dovecot and Spamassassin.

I noticed that Dovecot was putting all my "extra" IMAP folders in /home/user/mail/ and I thought this would be a nice place to put all mail, since Postfix was dumping them into /var/mail/user.

The problem is that I can get Dovecot to switch over because it has a configuration item like:
mail_location = /home/%u/mail/

However, it appears that Postfix doesn't allow for variables such as %u (username), so I'm frankly at a loss as to how I can redirect incoming mails to /home/username/mail/inbox. I tried a google search, and one person recommended changing the environment variables for MAIL to MAIL=/home/username/mail/inbox. Didn't seem to work tho. Maybe I did something wrong, I dunno. Either way, doing this for a few users might not be too horrible, but there's got to be a cleaner way.

Can anyone help me out here?

Also, Spamassassin is great and all, but it doesn't make any damn sense to have a spam filter that highlights the spam and puts it in my inboxes anyway. Is there any way to get those spam mails sent to /home/user/mail/Spam instead?

Locust76 on

Posts

  • Locust76Locust76 Registered User regular
    edited February 2011
    I'm gonna bump this once (and only once) because I refuse to believe that nobody here knows anything about mail servers.

    Locust76 on
  • EchoEcho ski-bap ba-dapModerator, Administrator admin
    edited February 2011
    Is there any advantage for you to having IMAP stuff in each userspace? The purpose of IMAP is remote access without local download of mail; having it in userspace is more of a POP3 method.
    Locust76 wrote: »
    Also, Spamassassin is great and all, but it doesn't make any damn sense to have a spam filter that highlights the spam and puts it in my inboxes anyway. Is there any way to get those spam mails sent to /home/user/mail/Spam instead?

    Look at procmail and write some rules that filter it based on the headers Spamassassin injects.

    Spamassassin just flags stuff as spam/ham; any filtering will have to be done further down the chain.

    Echo on
  • JHunzJHunz Registered User regular
    edited February 2011
    Not exactly on-topic for your question, but if this is your first mail server please ensure that you're not acting as an open relay. Some mail software (I don't know whether this includes the one you're using) is configured this way by default, and nothing beats waking up one morning and realizing that you've been facilitating spam because a bunch of blacklists just added you.

    JHunz on
    bunny.gif Gamertag: JHunz. R.I.P. Mygamercard.net bunny.gif
  • Locust76Locust76 Registered User regular
    edited February 2011
    As far as I can tell, I'm not acting as an open relay. I have it set up to use SSL connections and username/password verification to send via SMTP. Is there any way to positively check if I'm running securely? (I've also got no funny activity in my logs)

    True, I want to have the server primarily IMAP based, but I was kind of thrown off by the fact that my mail folders were pretty much strewn about the file system instead of all in a neat and orderly directory structure such as /home/username/mail

    It would just be easier for me to deal with if everything was organized. I had read about procmail, I think I'll give that a shot.

    I also just installed amavisd-new. From what I understand, amavisd is a sort of broker between the MTA and filters, so it would be easier and more efficient to hook everything into amavisd instead of trying to get everything wormed into postfix, right?

    Edit:

    actually it looks like someone did try and use my shit as a relay:
    Feb 14 06:59:29 hostname postfix/smtpd[26776]: connect from unknown[93.48.242
    .15]
    Feb 14 06:59:29 hostname postfix/smtpd[26776]: NOQUEUE: reject: RCPT from unk
    nown[93.48.242.15]: 554 5.7.1 <info@sbiancante.com>: Relay access denied; from=<
    rella5@katamail.com> to=<info@sbiancante.com> proto=SMTP helo=<none>
    

    I should be in the clear, right?

    Locust76 on
  • Jimmy KingJimmy King Registered User regular
    edited February 2011
    Postfix comes set up pretty intelligently out of the box with Debian, fortunately.

    As to moving where mail is stored, I believe you just need to add the following line to your /etc/postfix/main.cf:
    mail_home = mail

    The mail_home directive will change the mail file to whatever you put there relative to the user's $HOME. I'm not 100% certain this will do what you need as I always use a qmail style Maildir/ setup, but I think this will work.

    Jimmy King on
  • Locust76Locust76 Registered User regular
    edited February 2011
    Thanks a lot Jimmy, that appears to do exactly what I need it to do, though the variable should have read:

    home_mailbox = mail/inbox

    that way all mail is being appended to the file inbox which is located in /home/username/mail. Yay, it's organized!

    I also had to reconfigure dovecot to get mail out of this file, which threw me off for a second, because I saw that postfix was doing the right thing. Maybe I should stop consuming alcohol when playing around with my mail server :)

    Locust76 on
  • Jimmy KingJimmy King Registered User regular
    edited February 2011
    bah, and I had just looked at the name of the parameter like 2 minutes before posting that and I still got it mixed up.

    But yeah, that looks right. I wasn't sure if /home/<user>/mail was a dir or the actual file. Like I said, I haven't run it like that in a long time.

    Anyway, glad it's working for you. Now when are you going to get to the fun stuff and enable tls/ssl for it? Thats actually nice and easy with Debian. Back when I first did it on Slackware you had to download the postfix source and a couple of third party patches.

    As to spamassassin, yes, there is a way to do what you want. I had that set up on an old server although I don't bother with it now. I believe I had to fiddle about with procmail to get it to do that. I'll dig to see if I've still got the old config files backed up somewhere.

    Actually, something along the lines of this is probably what you need. http://wiki.apache.org/spamassassin/UsedViaProcmail

    Jimmy King on
  • Locust76Locust76 Registered User regular
    edited February 2011
    Actually, fiddling around with the encryption certificates was one of the first things I did. I managed to inadvertently get it to work using only username/password authentication for sending and receiving, then it was just a matter of switching from non TLS/SSL over to TLS/SSL connections. I spent some time on Saturday getting that set up, as well as RoundCube Mail as a web interface ;)

    I just installed the amavisd, spamassassin, clamav trifecta and it seems to be working very well. Just gotta get the spamassassin mails to move into the Junk Email file automatically and I'll be good to go. I did happen to notice that procmail (at least as far as it's described in online blog posts) wants to deposit mails (perhaps as individual files) in a folder, instead of appending them to a text file like my current setup. Is this so, or can this be changed around?

    I'm not quite sure how I stand on that issue. On the one hand, just having 5 or so big files makes backups a lot easier, but on the other hand, it makes finding individual emails a bitch.

    I'll have to take a look at all that tomorrow... bed's calling!

    Locust76 on
  • Jimmy KingJimmy King Registered User regular
    edited February 2011
    I think it'll work ok for you. I'm using qmail style delivery which has separate files for each e-mail, but there's not actually a separate directory for each folder. I'm using courier imap and it just has a file in my mail directory which lists the names of the folders, so it has INBOX.Trash, INBOX.Junk, INBOX.Sent, and so on listed in it which is how some other examples I looked at showed it. So you can probably just specify INBOX.Spam or whatever for the folder. That's what I'd try anyway.

    Jimmy King on
  • Locust76Locust76 Registered User regular
    edited February 2011
    I switched over to MailDir format and that seems a little more logical, though I don't understand why Sent, Drafts, Trash, etc... are all in .Hidden directories... meh, whatever. Anyways, I tried setting amavisd to pass all spam with
    $final_virus_destiny      = D_PASS;
    $final_banned_destiny     = D_PASS;
    $final_spam_destiny       = D_PASS;
    $final_bad_header_destiny = D_PASS;
    

    which seemed to stop it from outright deleting spam, but when passed along to Maildrop (installed it last night), it doesn't seem to react to the X-Spam: Yes field like it should:
    ###Redirect Spam to Maildir/.Junk E-mail
    if (/^X-Spam-Status: Yes/ )
    {
    to "Maildir/.Junk\ E-mail"
    }

    Maybe I actually need to name it .Spam instead of .Junk\ E-mail... lord only knows if that even works...

    Locust76 on
  • Locust76Locust76 Registered User regular
    edited February 2011
    So it gets weirder. I decided to delve into the processes a little bit and try to manually pass a spam-flagged email to my test account via Maildrop to see if it even works. Maildrop does the following (/etc/maildroprc):
    # Global maildrop filter file
    
    # Uncomment this line to make maildrop default to ~/Maildir for
    # delivery- this is where courier-imap (amongst others) will look.
    DEFAULT="$HOME/Maildir"
    
    # commands and variables for making the mail directories
    maildirmake=/usr/bin/maildirmake
    mkdir=/bin/mkdir
    rmdir=/bin/rmdir
    MAILDIR=$DEFAULT
    
    # make the user's mail directory if it doesn't exist
    `test -e $DEFAULT`
    if ($RETURNCODE != 0)
    {
    `$mkdir -p $MAILDIR`
    `$rmdir $MAILDIR`
    `$maildirmake $MAILDIR`
    }
    
    # make the .Junk folder if it doesn't exist
    JUNK_FOLDER=.Junk
    JUNK_DEST=$MAILDIR/$JUNK_FOLDER/
    `test -d $JUNK_DEST`
    if ($RETURNCODE != 0 )
    {
    `$maildirmake $JUNK_DEST`
    #auto subscribe. the following works for courier-imap
    
    #`echo INBOX.Junk >> $MAILDIR/courierimapsubscribed`
    `echo "Junk" >> $MAILDIR/subscriptions`
    }
    
    # If the Spam-Flag is set, move the mail to the Junk folder
    if ( /^X-Spam-Flag: YES/ )
    {
    exception {
    to $DEFAULT/.Junk/
    }
    }
    

    TL;DR, this is a config I downloaded and modified only slightly. It sets some variables, checks for the Maildir and .Junk folders and then checks if the mail is marked X-Spam-Flag: YES, and if so, move to Maildir/.Junk.

    I tried it on my test account, but it kept sending the mails into my regular inbox. It was failing the Maildir and .Junk folder checks, which was weird, because the Maildir was there, so I manually created the /home/testuser/Maildir/.Junk. Suddenly, every time I passed a spam mail it came into the Junk mail folder, just like it should. If I look at the log, Maildrop says the Maildir and .Junk folder tests now pass, even though I only added the .Junk folder. I've tried different permutations of the Maildir variable (with and without trailing slash, etc..), but it still fails if .Junk isn't there in my regular "live" account. Directory permissions are the same in both cases (user:user, drwx
    ).

    So that's problem one. Problem two is that even though I have:
    maildrop  unix  -       n       n       -       -       pipe
      flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
    

    in /etc/postfix/master.cf, it's still somehow not being called properly and emails that go to my test account seem to bypass maildrop entirely and get dropped straight into my inboxes anyways.

    Got any tips?

    Locust76 on
  • Locust76Locust76 Registered User regular
    edited February 2011
    Solved Problem two! Had to add the line
    mailbox_command = /usr/bin/maildrop
    

    to /etc/postfix/main.cf and give postfix a good reload. After that, it was properly filtering mails through maildrop. The automatic creation of folders via Maildrop doesn't work for some reason, but I added the folders to /etc/skel, so any future users should have the appropriate folders to start out with, so it's probably not that big of a deal.

    Locust76 on
  • Jimmy KingJimmy King Registered User regular
    edited February 2011
    Well, looks like I was a bit late checking back, but good to see you've got it sorted out.

    Jimmy King on
Sign In or Register to comment.