From charlesreid1

This page documents my adventure in setting up a working Postfix mail server that resides on my home server.

Installing

One of my goals was to get a mail server working so that I could send out emails through MediaWiki. In order to get this all working, I had to install several pieces of software.

Postfix

I used the following website to help me get Postfix and Dovecot installed: http://www.mysql-apache-php.com/#mailserver

I used aptitude to install Postfix:

$ apt-get install postfix postfix-tls

This installs postfix, and a patch for postfix that incorporates support for TLS (TLS is transport layer security wikipedia:Transport Layer Security, a child protocol of wikipedia:Secure Socket Layer). It is used by Postfix to encrypt sessions (see http://www.postfix.org/TLS_README.html).

Next, I needed to install SASL (wikipedia:Simple Authentication and Security Layer), which is used by Postfix as part of authentication (see http://www.postfix.org/SASL_README.html):

$ aptitude search sasl
$ apt-get install sasl2-bin libsasl2-2 libsasl2-modules libsasl2-dev

And just for good measure (see website referenced above):

$ apt-get install popa3d

which is a small POP3 daemon designed for security.

Next, the Postfix configuration file is located at /etc/postfix/main.cf, or in your installation prefix if you installed from source.

Finally, if you want to restart your Postfix server, you can run

$ /etc/init.d/postfix restart

or, wherever your Postfix has been installed. Different Linux distros will put it in different places.


Dovecot

I installed Dovecot, which is a POP3 and IMAP server. It uses Postfix as a mail transfer application, and it provides the POP3 and IMAP interface.

A really slick way to use this feature is to set up your Gmail to check email from your POP or IMAP server, so you get your domain email delivered directly to your inbox. You can also set up Gmail so that you can send email from your domain email address.

$ apt-get install dovecot-common dovecot-imapd dovecot-pop3d dovecot-dev

Next, if you want to edit the Dovecot configuration file, it's located at /etc/dovecot/dovecot.conf. I changed/added the following lines:

# specify protocols = imap imaps pop3 pop3s
protocols = pop3 imap

# uncomment this and change to no.
disable_plaintext_auth = no
pop3_uidl_format = %08Xu%08Xv

And finally, to restart Dovecot, run

$ /etc/init.d/dovecot restart


SASL Authentication + TLS

This is a way to protect a mailserver from being used by spammers. It requres authentication of users before it sends emails out.

The first step is to set up SMTP authentication (using SASL) with Postfix and Dovecot.

In the file /etc/postfix/main.cf:

smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = yourdomain.com
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_security_options = noanonymous

This will require you to set the variable mynetworks, and will not allow anyone outside of "mynetworks" to use your mail server.

In the file /etc/dovecot/dovecot.conf:

First, rename the line starting with "auth default" to "auth default2".

Before that line, put this block:

auth default {
  mechanisms = plain login
  passdb pam {
  }
  userdb passwd {
  }
  socket listen {
    client {
      path = /var/spool/postfix/private/auth
      mode = 0660
      user = postfix
      group = postfix
    }
  }
}

You'll now have to restart the SASL authentication daemon, Postfix, and Dovecot (with root privileges):

$ /etc/init.d/saslauthd restart
$ /etc/init.d/postfix restart
$ /etc/init.d/dovecot restart

Also remember that you should open up port 25 (or whatever port you end up using for your email server) in your Firewall. (And if you don't have a firewall, GET ONE!!!)

PHP Pear

Pear is a way of extending the functionality of PHP. In my case, I had to install a Pear module named Mail in order to get MediaWiki's mail functionality working. The Mail module depends on a couple of other modules. I ran the following commands to install these:

$ pear install Net_Socket
$ pear install Auth_SASL
$ pear install Net_SMTP
$ pear install Mail

This was using my installed-from-source version of PHP, which was already on my $PATH. You can also use a package manager like aptitude or yum to install PHP, e.g. apt-get install php. This will automatically install Pear.

If you set up authentication for your SMTP server (e.g. when you set up Postfix), then you'll need to edit the corresponding Pear PHP files to add the username and password. The smtp.php file (which you'll have to edit) should be at /path/to/php/lib/php/Mail/smtp.php.

Finally, I had to add this to my php.ini file:

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail


MediaWiki

You can find mail-related notification settings for LocalSettings.php here: http://www.mediawiki.org/wiki/Manual:Configuration_settings#Email_settings







References

http://www.macos.utah.edu/documentation/system_utilities/superduper_diskutil_and_log_script.html

http://www.mediawiki.org/wiki/Manual:Configuration_settings#Email_settings

http://chris.brandlehner.at/Brandlehner/cab_blog.nsf/d6plinks/DOMO-6KJH4T

http://www.mysql-apache-php.com/#mailserver

http://souptonuts.sourceforge.net/postfix_tutorial.html

http://prantran.blogspot.com/2007/01/getting-postfix-to-work-on-ubuntu-with.html

http://www.google.com/support/forum/p/Google%20Apps/thread?tid=0cce162b213f7e66&hl=en

http://blog.sethladd.com/2007/08/using-gmail-to-relay-email.html

http://www.linuxquestions.org/questions/linux-software-2/postfix-cannot-send-e-mail-186776/

http://www.postfix.org/postconf.5.html


http://en.gentoo-wiki.com/wiki/Mailman_with_Postfix_and_Dovecot