Setup mail hosting on Debian Squeeze and other distros using postfixadmin

Postfix is our favorite mail server. We find it's easy to configure and performs really well. When asked at a recent conference talk, Eric Allman the creator of Sendmail, said he would use Postfix if starting today.

Many people ask us if there is an easier way to setup and manage email address and aliases, especially when managing several domains. We have found PostfixAdmin does the job nicely. It's a bit of work to setup the database and integrate it in with all the other mail related programs. Here at Rimuhosting, we have spent some time recently to create a script to install and integrate these applications:


This script was engineered to start with a fresh Debian Squeeze VPS, and set it up with a complete mail hosting solution which Includes Postfix, Dovecot, SpamAssassin, and Roundcube.

The script has some options, so if you don't want to install everything you don't have to. Check the "-help" option for more info:

bash installpfa-squeeze.sh -help
 
Usage: installpfa-squeeze.sh [OPTION...]
 
installpfa-squeeze.sh will attempt to install all configurations for postfixadmin by default,
assumes that the current postfix and dovecot configurations are the base ones in 
Debian Squeeze. It will use default settings for usernames and database names. 
It will generate random passwords and the relevant ones will be informed. 
 
 
Options:
 -a <email>	email address to used as admin user in postfixadmin. DEFAULT: admin@motu.nimhq.net
 -p <password>	password to be setup for the admin user in postixadmin. DEFAULT: RANDOM
 -j <dbuser>	postfixadmin mysql database username to be setup. DEFAULT: postfixadmin
 -k <dbpass>	postfixadmin mysql password to be assigned to the mysql database user. DEFAULT: RANDOM
 -d <dbname>	postfixadmin mysql database name. DEFAULT: postfixadmin
 -q <dbuser>	roundcube mysql database username to be setup. DEFAULT: roundcube
 -w <dbpass>    roundcube mysql password to be assigned to the mysql database user. DEFAULT: RANDOM
 -e <dbname>	roundcube mysql database name. DEFAULT: roundcube
 -v <user>	name of the unix user that will hold the mailboxes. DEFAULT: vmail
 -f		force the install, prompts in error/warnings are disabled. export MYSQL_ROOT_PASS=password 
		can be used with this setting for unattended installs.
 -h		this Help
 
Advanced Options:
 -t <task1,task2>	Comma separated of tasks to execute manually, may depend on the above 
			options. DEFAULT: all
 Possible Tasks:
   install_deps			installs postfixadmin dependencies
   install_pfadmin		downloads and installs postfixadmin package
   configure_pfa_database	configures postfixadmin database
   configure_pfadmin		configures postfixadmin
   add_pfa_admin_user		adds admin user to postfixadmin
   configure_dovecot		configures dovecot
   configure_spamassassin	configures spamassassin
   configure_postfix		configures postfix
   install_roundcube		installs roundcube
   configure_roundcube		configures roundcube

There is also an script that is designed to be non-distribution specific, but due the nature and complexity of the current script it will likely be unmaintained, and also lacks some features. For those interested it is located at:

If your looking to setup some mail hosting, especially if your managing multiple domains, order a new Squeeze VPS, and just let us know you would like PostfixAdmin setup, and we will go do that for you.

This entry was posted in Featured, Rimuhosting and tagged , , , , , , . Bookmark the permalink.

31 Responses to Setup mail hosting on Debian Squeeze and other distros using postfixadmin

  1. I downloaded your script, thanks for providing it! I got a couple of errors when running it. I could not find where in the script (or in the referenced installmysql.sh script either) these file downloads are referenced to update them to the current/latest versions.

    Missing file = python-minimal_2.6.6-3+squeeze5_all.deb
    Replace with = python-minimal_2.6.6-3+squeeze6_all.deb

    Missing file = python_2.6.6-3+squeeze5_all.deb
    Replace with = python_2.6.6-3+squeeze6_all.deb

    Missing file = dbconfig-common_1.8.46_all.deb
    Replace with = dbconfig-common_1.8.47_all.deb

    The script fails at that point so I don't know if there are any other files that need updated as well.

    Thanks again!

    h

    • Juan Rossi says:

      Hi,

      Keep in mind that the script is more oriented to setup postfixadmin in our VPSs, but should work as well in other systems. For the error that you have posted my guess is that is related to apt-get, not the script, did you run apt-get update first?.

      Also it will be awesome if you can provide the script output, with some scope, so we can pin point where is failing,

      Thanks.

      Juan.-

  2. Forgot to mention that I noticed that PostfixAdmin is updated to 2.3.3, so when I downloaded the script I changed that as well. Leaving it at 2.3.2 did not make a difference.

    Thanks!

    h

  3. **** NOTE ****
    OK, looks like it pasted fine, but the comment manager appears to be interpreting parts of the script and not displaying it. I'll post a link to it you can download if you wish.
    **** NOTE ****
    **** JUAN ROSSi NOTE ****
    Deleted redundant posts and kept this one.
    **** JUAN ROSSi NOTE ****

    Juan, thanks for replying, I didn’t realize until I re-read the post that it was designed for your VPS installations.

    The issue must have been the apt-get update, I use VMware for my server images and I think my template is a couple of weeks old, so there may have been updates since then that I didn’t capture. I added apt-get update to the script so it automatically updates as the first part of running the script.

    As mentioned above, I also updated the script for PostfixAdmin 2.3.3.

    During the install I noticed a failure because php5-mysql was not installed, I added this to the script as well. The new script is at http://blog.dnjhome.com/installpfa-squeeze.sh. I won’t include the script output because it completed successfully.

    I did notice some grammar errors in the output/comments that I fixed as well :-)

    Thanks!

    h

  4. Juan Rossi says:

    @withanHdammit : awesome incorporated some of the changes, but in the install_deps method needs more work to be generic, like installing the packages from the dependency list of postfixadmin package. Sadly I cannot incorporate this yet, because the script also should feature a non interactive mode, with packages preseeded. We have these packages already installed in our VPSs, and they will have preseeds, that why didn't add that yet.
    If some of the packages in the deps asks for questions they need to be answered by putting preseeds, and if not, there will a bug there.
    Now we have your name in out version history :). The script will be updated in our repos in an hour or so.

  5. Awesome, glad I could contribute! I really appreciate your script, I've been struggling with getting a Postfix/Dovecot/RoundCube/PostfixAdmin server dialed in and your script was exactly what I needed.

    Thanks for including me!

  6. Christian says:

    Hello, I find it very good the script is more, use it and I installed everything perfectly! I just would fail to configure per-user quotas, as and followed several tutorials and I could not configure them. Putting example:
    usuario1@dominio.com: 10 mb
    usuario2@dominio.com: 5 mb
    usuario3@dominio.com: 15 mb
    No how, because follow several tutorials and I could not configure it. I would need to pass a configuration if you already have created so I put in my SeverMail.
    Thank you very much for everything!

    Chris

  7. Juan Rossi says:

    QChris,

    In the current postifxadmin configuration quotas are not enabled. But if you wish to enforce them, you will have to configure it in postfixadmin and dovecot. At the moment it does not support it, but there are many posts on the web about it:

    http://wiki.dovecot.org/MainConfig
    http://www.dovecot.org/list/dovecot/2006-September/016478.html
    http://wiki.dovecot.org/HowTo/DovecotLDAPostfixAdminMySQL

  8. Grimmis2k says:

    I like the script but I am getting a failure when running it:

    The following packages have unmet dependencies:
    postfix-mysql : Depends: postfix (= 2.7.1-1+squeeze1) but it is not going to be installed
    E: Broken packages
    ./installpfa-squeeze.sh: line 71: postconf: command not found
    Error: Postfix does not have mysql support

    Any Ideas!

    • Liz Quilty says:

      Heya, are you running Debian Squeeze? it may be that the packages have changed or you have custom packages installed. Basically you just need to install postfix-mysql , you can use apt-cache search postfix mysql and see if you can find a package to install .
      I will get Juan to check/test the script when he gets back from holiday or if we have downtime this weekend

  9. Gam Boi says:

    Grimmis2k: to avoid this: postfix-mysql : Depends: postfix (= 2.7.1-1+squeeze1) but it is not going to be installed
    do sudo apt-get install postfix before you run the script from this page.

  10. Juan Rossi says:

    Hi

    @Grimmis2k, the script is mainly designed to run well on our VPSs, which come with postfix installed by default.
    There is no preseed in the script to install postfix unattended, so as @Gam Boi suggests, install postfix first:

    # apt-get install postfix

    I have tested the script again in a freshly installed rimu VPS with debian squeeze, and the task for dependencies went well.

  11. Mopsy says:

    Hey, I've used this script in the past, and last time, it worked wonders. I tried (starting a few days ago) to get this script working again, and this time around, no matter what I do, and no matter how many times I've reinstalled, I keep getting "Authentication Failed" in Thunderbird, and errors like: `dovecot: pop3-login: Disconnected (auth failed, X attempts)` in my mail logs. I've gone through this so many times over, I'm not sure what's wrong, or even what information I should provide, other than that I'm using a fully up-to-date Debian Squeeze.

    • Liz Quilty says:

      If this is on a VPS of ours we can take a look at the setup, just drop us an email at support. It sounds like the config may be slightly broken, it would be good to see where it went wrong and be able to fix it.

  12. Mopsy says:

    This is actually on a box in my house that I use as secondary DNS, and intend to use as mail. I've just known this script to be utterly excellent in the past, and I don't know what's not right now. Weirdly enough, I dug up my old copy of this script (one I know to have worked), and it doesn't work anymore either. I imagine it's being caused by some sort of update in one (or multiple) of the packages or something. Not sure. Also, I did make sure to apt-get update && apt-get upgrade && apt-get install postfix before using the script. And again, I've tried this several times; I'm truly at a loss, and mail is one of the few things I don't know how to do manually.

    If you're still curious to find out what's wrong, or help me, I'll be happy to provide any conf files you might be interested in. Either way, I appreciate you getting back to me. =]

  13. digitalirony says:

    After running this script, it appears that the postfixadmin DB is blank. I do not see anywhere in your script where this seems to be initiated. Am I missing something?
    I see where you initiate the DB for roundcube, as there is an sql dump for doing so inside the script.
    How am I supposed to have the postfixadmin DB created?
    Also, This doesn't work out of the box if you are running suexec with php. You may have to do something like:
    apt-get install acl
    mount -o remount,acl /dev/sdxX where xX are your partitions.
    setfacl -m u::r /etc/postfixadmin/config.inc.php

    Also, the usernames and passwords are output to the screen a little early, and are somtimes missed. Would be nice to have a good summary at the end with whatever has changed/created.

    • Juan Rossi says:

      @digitalirony
      There is a web query that populates the database:

      wget -q 'http://localhost/postfixadmin/setup.php' -O /dev/null

      Keep in mind that the script is mainly designed and tested in our base Debian Squeeze VPS images, and php suexec is not configured.
      I will add as a feature request for the script to repeat the usernames information at the end every time.

  14. Hey,
    So cool, i just bought a debian squeeze vps from rimu, and was looking to setup postfix/mysql/postfixadmin. Definitely going to try using this script.

    Thanks Rimu.

  15. Engin YILMAZ says:

    Hey, thank you for this great script. I can now connect to my server from outside and can easily pop and send mail using programs such icedove, thunderbird, .. etc.

    But the PHP's mail function does'nt seem to work. PHP's mail function can send mail to local mail accounts but cannot send to outside accounts. Also in localhost I can't send mail to outside with icedove but can receive mail.

    Possible causes of the problem which I suspect:
    *My MX records were set outside from freedns.afraid.org may it be the origin of the problem?
    *Could /etc/

    Please help me I have beent strugling with the mail settings about 10 days.

    • Liz Quilty says:

      Heya, best place to check that in in the mail log which will be in /var/log/mail.log or similar. Potentially the path or setup is different on your server to the one this was written on also. If you are a customer of ours pop in a ticket and we can take a look at that for you no problem

  16. Engin YILMAZ says:

    Hia, when I connect from other machine with Thunderbird I can easily send mail relay'in on my mail server.

    But when I try to send mail directly over the Mail Server the message is queed and the mailq exposes such message.
    ----
    731AD12070A 626 Fri Jul 13 10:05:15 sender@mydomain.com
    (connect to mx1.hotmail.com[65.54.188.126]:25: No route to host)
    receipent@hotmail.com
    ----

    Small Note: I changed the receipent and the sender addresses.

  17. Engin YILMAZ says:

    Hello Liz, unfortunately I am not one of your customer and I am out of your network. Still do you tink I should I open a ticket ? Also you may sell me a ticket for one time only?

  18. Engin YILMAZ says:

    Okay thank you. After nearly 20 days of strugling I give it up and relayed to Google's SMTP.

  19. egdels says:

    thank you! works like a charm. i only had to change

    IP_ADDRESS=$(ifconfig eth0 | grep 'inet addr:' | sed 's/.*inet addr:\([0-9.]*\) .*/\1/g' )

    in

    IP_ADDRESS=$(ifconfig venet0:0 | grep 'inet Adresse:' | sed 's/.*inet Adresse:\([0-9.]*\) .*/\1/g' )

    because of my german system and missing device eth0. i also changed default http port 80 since my webserver is behind a reverse proxy forwarding to a different port.

  20. Ruud says:

    Thanks for this nice script. So far it is working. I am not one of your customers.
    I have only a problem with the option to add a domain for backup domain. I am able to add the domain, but when postfix recieves a message for the backup domain, it returns a smtp error like user or recipient unknown in virtualtable.

    I do not want to configure all e-mailaddressess of the users while its only a backup domain. I gues it should check every hour if the higher mx record of the domain is listening again and drop its mail.

    In /etc/postfix/main.cf i have:
    virtual_transport = dovecot

    I gues this has to be something else? Do you have a solution for it?

    • Juan Rossi says:

      Hi,

      For doing backup MX, postfix requires a special configuration, I do not think virtual_transport = dovecot will be related for doing this.

      Try the following per /usr/share/doc/postfixadmin/DOCUMENTS/BACKUP_MX.txt


      1. Modify main.cf
      -----------------
      In order for Postfix to use MySQL for relay_domains add the following
      to your main.cf

      relay_domains = proxy:mysql:/etc/postfix/mysql_relay_domains_maps.cf

      2. mysql_relay_domains_maps.cf
      ------------------------------
      You will need to put this into a text file for postfix to pickup.

      user = postfixadmin
      password = XXXXXXXXXXX
      hosts = localhost
      dbname = postfixadmin
      query = SELECT domain FROM domain WHERE domain = '%s' AND backupmx = '1'

      3. Restart Postfix
      -------------------
      When you are done make sure to restart Postfix so the changes take effect.

  21. ruhan says:

    Dear Ri-Mu,

    how to enable vacation module for postfixadmin ?? bacause i using your script i little confuse about this. Thank You.

    Regards
    Ruhan

    • Juan Rossi says:

      @ruhan

      Have a look at the documentation located at /usr/share/doc/postfixadmin/examples/VIRTUAL_VACATION/INSTALL.TXT.gz

      • ruhan says:

        @Juan

        Thanks for helping to solve this problem :)
        and now my server running well with vacation include using postfixadmin :D