Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
virtual mail - useradd script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
wanie
n00b
n00b


Joined: 03 Jun 2011
Posts: 9
Location: Germany

PostPosted: Fri Jun 03, 2011 10:10 am    Post subject: virtual mail - useradd script Reply with quote

Hi,

I was building my own mailserver in reference to this great howto:
http://www.gentoo.org/doc/en/virt-mail-howto.xml

The Server works with all of my 6 domains, but there is a question about the user-administration.
If i will get a new user account on this server, so i have to do the following thins:
- make a dir in /home/vmail/foo.bar/user
- make a maildir in /home/vmail/foo.bar/user/.maildir

and now the really hard work: login to phpmyadmin and add the user in table users, but not just once.
Because i have 6 domains, that all route to the same mailserver, i have to add one user with 6 different domains in table users, like that:
user@foo.bar; password; /home/vmail; /home/vmail/foo.bar/user/.maildir;
user@foo1.bar; password; /home/vmail; /home/vmail/foo.bar/user/.maildir;
.
.
.
user@foo5.bar; password; /home/vmail; /home/vmail/foo.bar/user/.maildir;

I think this is very fault-prone for case, you are in hurry and forget every small thing...
So is there any workarround to handle this virtual-mail solution with a lot of accounts?

How schould i do this, what is the right way?
Something like a php-script that handle alle of these 6 domains at just one (because every account use all af these domains).
Or something like a bash script to make the folders/maildirs an connect to mysql to add 6 accounts per one user?
Any other Ideas?

I'm grateful for any help.

So long,
wanie
Back to top
View user's profile Send private message
Anarcho
Advocate
Advocate


Joined: 06 Jun 2004
Posts: 2967
Location: Germany

PostPosted: Fri Jun 03, 2011 1:20 pm    Post subject: Reply with quote

I wonder why you need 6 accounts? You could just add 5 domains as domain-alias to the first one.
_________________
...it's only Rock'n'Roll, but I like it!
Back to top
View user's profile Send private message
wanie
n00b
n00b


Joined: 03 Jun 2011
Posts: 9
Location: Germany

PostPosted: Fri Jun 03, 2011 8:21 pm    Post subject: Reply with quote

Hi Anarcho,

that would be great, i tried this allready.
I added in alias table the domain foo1.bar as alias, with destination to foo.bar.
When i try to send a mail to user@foo1.bar i got the following error:

Message not sent. Server replied:

Requested action not taken: mailbox unavailable
550 5.1.1 <user@foo1.bar>: Recipient address rejected: User unknown in virtual mailbox table

The postfix log is pretty much the same:

Jun 3 22:07:39 mail postfix/smtpd[9234]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 550 5.1.1 <user@foo1.bar>: Recipient address rejected: User unknown in virtual mailbox table; from=<me@foo.bar> to=<user@foo1.bar> proto=ESMTP helo=<mail.foo.bar>
Jun 3 22:07:39 mail postfix/smtpd[9234]: > localhost[127.0.0.1]: 550 5.1.1 <user@foo1.bar>: Recipient address rejected: User unknown in virtual mailbox table

Do you have any tipps for me to trying out?

The complete config of the services is really like the config in the Howto.
Back to top
View user's profile Send private message
Anarcho
Advocate
Advocate


Joined: 06 Jun 2004
Posts: 2967
Location: Germany

PostPosted: Fri Jun 03, 2011 10:05 pm    Post subject: Reply with quote

In my MySQL-Backend for virtual alias table I have to enter it like "@foo1.bar" and "@foo.bar". Maybe you missed the @-signs?
_________________
...it's only Rock'n'Roll, but I like it!
Back to top
View user's profile Send private message
wanie
n00b
n00b


Joined: 03 Jun 2011
Posts: 9
Location: Germany

PostPosted: Fri Jun 03, 2011 11:54 pm    Post subject: Reply with quote

Thank's for the tip, but it doesnt't work for me.
Same error message.

The main reason is, that people should administrate the server (add/del user account's), who don't really know, how to create maildir in linux, and thinks like this.
So it's hard to teach this guys, for use the phpmyadmin and go to the shell for adding maildirs and user folders.

Think i would write any php Admin page in wich, one can see/add/del all accounts.

Just hope that there is allready anything out like this, but i guess not right now...
I Know there is something like that for qmail (qmailAdmin), but unforunately i can't find everything like this for my intention.
Back to top
View user's profile Send private message
Anarcho
Advocate
Advocate


Joined: 06 Jun 2004
Posts: 2967
Location: Germany

PostPosted: Sat Jun 04, 2011 12:20 pm    Post subject: Reply with quote

As I switched from Qmail to postfix a year and a half ago, I had the same problem. I created a little PHP/AJAX page to adminstrate the email and FTP accounts. It is rather simple but does the job for me.

And as far as I know you don't need to create the maildir folder yourself, I added in my script a function that sends a welcome-email to the new user and then postfix will automatically create the folders.

How are you implementing virtual alias? Per Mysql or per file? Could you post your configs?
_________________
...it's only Rock'n'Roll, but I like it!
Back to top
View user's profile Send private message
wanie
n00b
n00b


Joined: 03 Jun 2011
Posts: 9
Location: Germany

PostPosted: Sun Jun 05, 2011 12:35 pm    Post subject: Reply with quote

main.cf
------------------------------------------------------------
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = //usr/lib64/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
unknown_local_recipient_reject_code = 550
debug_peer_level = 2
debugger_command =
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /etc/postfix
readme_directory = no
myhostname = my.domain.tld
mydomain = domain.tld
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain $mydomain
mynetworks = 192.168.100.0/24, 127.0.0.0/8
home_mailbox = .maildir/
local_destination_concurrency_limit = 2
default_destination_concurrency_limit = 10
smtpd_sasl_auth_enable = yes
smtpd_sasl2_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_local_domain =
smtpd_recipient_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination
smtp_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_use_tls = yes
smtpd_tls_key_file = /etc/postfix/newkey.pem
smtpd_tls_cert_file = /etc/postfix/newcert.pem
smtpd_tls_CAfile = /etc/postfix/cacert.pem
smtpd_tls_loglevel = 3
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
alias_maps = mysql:/etc/postfix/mysql-aliases.cf
relocated_maps = mysql:/etc/postfix/mysql-relocated.cf
local_transport = local
local_recipient_maps = $alias_maps $virtual_mailbox_maps unix:passwd.byname
virtual_transport = virtual
virtual_mailbox_domains = our.domain1, our.domain2, ... our.domain6
virtual_minimum_uid = 1000
virtual_gid_maps = static:1001
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual.cf
virtual_uid_maps = static:1001
virtual_mailbox_base = /

If you need files like mysql-alias.cf, too, just let me know.
The virtual alias is based on MySQL i think.

The idea for let postscript add the maildir is realy gereat, and works for me! :-)
Thanks for the advice.

What is your workaround for deleting users?
Is there any way to let postfix delete/move the maildir, too?
Back to top
View user's profile Send private message
cach0rr0
Bodhisattva
Bodhisattva


Joined: 13 Nov 2008
Posts: 4123
Location: Houston, Republic of Texas

PostPosted: Tue Jun 07, 2011 11:26 am    Post subject: Reply with quote

if you're having to add the same user to every domain, then the approach is wrong

what i mean is this: the idea behind that "virtual mail hosting" howto, is that cach0rr0@domain1.com is a completely different human being from cach0rr0@domain2.com

Say, for example, I host mail for microsoft.com, and for gentoo.org

There may one person named Bill at each company. Bill Gates, who works for Microsoft, and Bill Cosby, who works for Gentoo.

In such a case, "bill@microsoft.com" and "bill@gentoo.org" need to be separate mailboxes, as they are obviously two different people.

But in your case - it sounds like you have multiple domains, but that you do not have any users who are unique only to one domain, as in, if you have a username 'bill', it's the same person for every mail domain.

IFFFF that's indeed the case, what you're doing is overkill. You could, in such a case, quite simply add a mailbox by adding a local user to the system, e.g. "useradd -m -G users cach0rr0", then set Postfix to simply validate recipients against /etc/passwd, setup courier or any other IMAP daemon to do the same, and look for new mail in /home/username/.maildir

Not sure how much of this necessarily applies to you, but if it does, there is a much easier way to go about things than having to manage a mysql database, manage virtual users, etc

If that is indeed relevant to you, I can happily post up an example main.cf for your perusal, and in my case I used (past-tense, i use cyrus now) dovecot, so a dovecot.conf as well
_________________
Lost configuring your system?
dump lspci -n here | see Pappy's guide | Link Stash
Back to top
View user's profile Send private message
Anarcho
Advocate
Advocate


Joined: 06 Jun 2004
Posts: 2967
Location: Germany

PostPosted: Tue Jun 07, 2011 11:38 am    Post subject: Reply with quote

Your file /etc/postfix/mysql-virtual.cf is interesting to know. I think I've done some tweaking here to enable domain alias:

Code:
user         = XXXXXXXXXXXXXXXXX
password     = XXXXXXXXXXXXXXXXX
dbname       = mailsql
table        = virtual
select_field = destination
where_field  = email
hosts        = unix:/var/run/mysqld/mysqld.sock
query = select destination from virtual where email = '%s'
      and left(destination,1) <> '@'
    union
    select destination from virtual where email = (
      select concat(left('%s',locate('@','%s')-1), destination) as rewritten
      from virtual where email = '@%d' and left(destination,1) = '@'
    ) and left(destination,1) <> '@'
    union
    select email from users where email = (
      select concat(left('%s',locate('@','%s')-1), destination) as rewritten
      from virtual where email = '@%d' and left(destination,1) = '@'
    )
    limit 1

_________________
...it's only Rock'n'Roll, but I like it!
Back to top
View user's profile Send private message
wanie
n00b
n00b


Joined: 03 Jun 2011
Posts: 9
Location: Germany

PostPosted: Tue Jun 07, 2011 10:03 pm    Post subject: Reply with quote

cach0rr0:
Yes it's right, i just using one account on all domains, for one and the same guy.
The Mailaccounts needs to be administrate (add/del accounts) verry easy, and primarily not by me in future.
Because of this I need something like a php interface for do these things, to make it easy to use.
I don't like the think for "useradd" real linux account with web-scripts via sudo or anything else.
This is the reason, wherefore i have to do this over MySQL.

Anarcho:
Thanks again!
Tomorrow I try out your tweaking and post the results.

her is the mysql-virtual.cf:
# mysql-virtual.cf

user = XXXXXXXXXXX
password = XXXXXXXXXXXX
dbname = mailsql
table = virtual
select_field = destination
where_field = email
hosts = unix:/var/run/mysqld/mysqld.sock
Back to top
View user's profile Send private message
cach0rr0
Bodhisattva
Bodhisattva


Joined: 13 Nov 2008
Posts: 4123
Location: Houston, Republic of Texas

PostPosted: Wed Jun 08, 2011 6:48 am    Post subject: Reply with quote

fair enough i suppose

if it's of any use to you, I've written a long detailed piece of documentation for a slightly different setup, but maybe its explanations will help you here - http://whitehathouston.com/documentation/gentoo/postfix_cyrus_vhost_howto.htm
_________________
Lost configuring your system?
dump lspci -n here | see Pappy's guide | Link Stash
Back to top
View user's profile Send private message
wanie
n00b
n00b


Joined: 03 Jun 2011
Posts: 9
Location: Germany

PostPosted: Wed Jun 08, 2011 7:37 pm    Post subject: Reply with quote

@cach0rr0
Thank you for the howto!

@Anarcho
Your modified config works great at my side! :-)
To add a new mail-account i now have to add just one user in virtual-users table, and the server accept mails for this user@all-my-domains.

My small, but nice php interface ist working correctly now, too.
I have to do some security and performance checks the next few days.
Then I look forward to make my server public reachable next week.

Thank you for these helpful tips!
Back to top
View user's profile Send private message
Anarcho
Advocate
Advocate


Joined: 06 Jun 2004
Posts: 2967
Location: Germany

PostPosted: Thu Jun 09, 2011 8:02 am    Post subject: Reply with quote

Good to hear that it's working.

I've gone all the way from qmail to postfix a year ago, so if you have further questions, please ask.

I have a little more complex setup as I integrated sympa as a mailinglist server as well and postfix takes lookups from the mysql database of sympa for alias etc. I wanted a lot of automation in the process.
_________________
...it's only Rock'n'Roll, but I like it!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum