# Permission problem with Postfix and MySQL [SOLVED]

## webbruno

Hi all,

I've followed the instructions  of Virtual Mailhosting System with Postfix Guide to set up a postfix mail server. I can send e-mails to my local users (and to other users on the internet as well) but the received e-mails are getting a different permission and in order to view the files on Squirrel I must change the permissions from 0644 to 0664, which means the new mails always are written with the 0644 permission. I'm using this script to add a user to my mailserver:

```

#! /bin/bash

USER=$1

useradd -s /sbin/nologin -G vmail,mail -m -b /var/mail/ ${USER}

maildirmake /var/mail/${USER}/.maildir/

chown ${USER}:${USER} -cR /var/mail/${USER}/

mysql --host=localhost --user=myverysecretuser --password=myverysecretpass mailsql << EOF

insert into users (email,clear,name, uid,gid,homedir,maildir) values("${USER}@zemarestaleiro.com.br","password","${USER}",1001,1001, "/var/mail/${USER}/","/var/mail/${USER}/.maildir/" );

EOF

passwd ${USER}

```

What am I missing or what am I doing wrong? Thanks in advance for all the help

----------

## audiodef

If you're not married to doing it that way, check out the Postfix guide linked in my sig. I think it would sidestep those problems by nature.

----------

## cach0rr0

I second the aforementioned guide, but them I'm a touch biased (actually, I may need to do an updated ebuild for cyrus-2.4.16, but dont have time at the moment)

specific to this:

 *webbruno wrote:*   

> in order to view the files on Squirrel I must change the permissions from 0644 to 0664, which means the new mails always are written with the 0644 permission. 

 

squirrelmail should be asking your IMAP server to read the mail file, and give it the contents

it should not be trying to read files from the filesystem directly, so unless something is amiss, squirrelmail *should* be permissions-agnostic - if the IMAP/POP server can read the emails, then so too, should squirrelmail be able to read them. 

so that's the spot to troubleshoot - first see if you can read the emails just via IMAP. Use telnet to test (list) if necessary, but make sure the IMAP piece is taken care of. Again, the variable here, squirrelmail should be asking IMAP, it should not be querying the filesystem directly.

It may even be as simple as changing the user under which the IMAP/POP daemon runs, to be the same user under which Postfix runs. 

This is part of why I found the "official" guide to be a bit cumbersome, and why cyrus with its internal account/mailbox structure ends up being easier to manage long-term.

----------

## webbruno

As I use to say: 90% of the problems in the computing world comes from somewhere between the chair (in this case, my own chair)[/b] and the keyboard, this one wasn't different. The error was obvious, I configured postfix to accept only connections from a specific uid: the vmail uid. The solution was the simplest:

Instead of creating system users I should create users using the mysql database linked with postfix as described in the tutorial

I really appreciate the help of you guys above!

----------

