<abstract>This document details how to create a virtual mailhosting system based upon postfix, mysql, courier-imap, and cyrus-sasl. </abstract>

11

<abstract>This document details how to create a virtual mailhosting system based upon postfix, mysql, courier-imap, and cyrus-sasl. </abstract>

12

<version>1.0</version>

12

<version>1.0.2</version>

13

<date>07 Jan 2003</date>

13

<date>7 Aug 2003</date>

14

<!--

14

<!--

15

15

16

Contents

16

Contents

17

17

18

I. Introduction

18

I. Introduction

…

…

35

<title>Introduction</title>

35

<title>Introduction</title>

36

<body>

36

<body>

37

<p>For most gentoo users, a simple mail client and fetchmail will do. However, if you're hosting a domain with your system, you'll need a full blown MTA (Mail Transfer Agent). And if you're hosting multiple domains, then you'll definitely need something more robust to handle all of the email for your users. This system was designed to be an elegant solution to that problem.</p>

37

<p>For most gentoo users, a simple mail client and fetchmail will do. However, if you're hosting a domain with your system, you'll need a full blown MTA (Mail Transfer Agent). And if you're hosting multiple domains, then you'll definitely need something more robust to handle all of the email for your users. This system was designed to be an elegant solution to that problem.</p>

38

<p>A virtual mail system needs to be able to handle email for numerous domains with multiple users over a variety of interfaces. This presents some issues that must be dealt with. For instance, what if you have two users on different domains that want the same user name? If you are providing imap access and smtp-auth, how do combine the various authentication daemons into a single system? How do you provide security for the numerous components that comprise the system? How do you manage it all?</p>

38

<p>A virtual mail system needs to be able to handle email for numerous domains with multiple users over a variety of interfaces. This presents some issues that must be dealt with. For instance, what if you have two users on different domains that want the same user name? If you are providing imap access and smtp-auth, how do combine the various authentication daemons into a single system? How do you provide security for the numerous components that comprise the system? How do you manage it all?</p>

39

<p>This howto will show you how to set up with a mail system capable of handling mail for as many domains as your hardware can handle, supports virtual mail users that don't require shell accounts, has domain specific user names, can authenticate web, imap, smtp, and pop3 clients against a single database, utilizes ssl for transport layer security, has a web interface, can handle mailing lists for any domain on the machine, and is controlled by a nice, central and easy mysql database. </p>

39

<p>This howto will show you how to set up with a mail system capable of handling mail for as many domains as your hardware can handle, supports virtual mail users that don't require shell accounts, has domain specific user names, can authenticate web, imap, smtp, and pop3 clients against a single database, utilizes ssl for transport layer security, has a web interface, can handle mailing lists for any domain on the machine, and is controlled by a nice, central and easy mysql database. </p>

40

<p>There are quite a variety of ways to go about setting up a virtual mailhosting system. With so may options, another may be the best choice for your specific needs. Consider investigating <uri>http://www.qmail.org</uri> and <uri>http://www.exim.org</uri> to explore your options. </p>

40

<p>There are quite a variety of ways to go about setting up a virtual mailhosting system. With so may options, another may be the best choice for your specific needs. Consider investigating <uri>http://www.qmail.org/</uri> and <uri>http://www.exim.org/</uri> to explore your options. </p>

<p>Make sure to turn on the following USE variables in <path>/etc/make.conf</path> before compiling the packages: <c>USE=&quot;mysql imap libwww maildir sasl ssl&quot;</c>. Otherwise you will most likely have to recompile things to get the support you need for all the protocols. Further, it's a good idea to turn off any other mail and network variables, like ipv6.</p>

44

<p>Make sure to turn on the following USE variables in <path>/etc/make.conf</path> before compiling the packages: <c>USE=&quot;mysql imap libwww maildir sasl ssl&quot;</c>. Otherwise you will most likely have to recompile things to get the support you need for all the protocols. Further, it's a good idea to turn off any other mail and network variables, like ipv6.</p>

45

<impo>This howto was written for postfix-2.0.x. If you are using postfix &lt; 2 some of the variables in this document will be different. It is reccommended that you upgrade. Some other packages included in this howto are version sensitive as well. You are advised to read the documentation included with packages if you run into issues with this.</impo>

45

<impo>This howto was written for postfix-2.0.x. If you are using postfix &lt; 2 some of the variables in this document will be different. It is recommended that you upgrade. Some other packages included in this howto are version sensitive as well. You are advised to read the documentation included with packages if you run into issues with this.</impo>

46

<impo>This document uses apache-1.3.x. Apache-2 has been marked stable in portage. However there are still a number of issues with php integration. Until php support in apache-2.0.x is marked stable, this guide will continue to use the 1.3.x version.</impo>

46

<impo>You need a domain name to run a public mail server, or at least an MX record for a domain. Ideally you would have control of at least two domains to take advantage of your new virtual domain functionality.</impo>

47

<impo>You need a domain name to run a public mail server, or at least an MX record for a domain. Ideally you would have control of at least two domains to take advantage of your new virtual domain functionality.</impo>

47

<impo>Make sure <path>/etc/hostname</path> is set to the right hostname for your mail server. Verify your hostname is set correctly with <c>hostname</c>. Also verify that there are no conflicting entries in <path>/etc/hosts</path>.</impo>

48

<impo>Make sure <path>/etc/hostname</path> is set to the right hostname for your mail server. Verify your hostname is set correctly with <c>hostname</c>. Also verify that there are no conflicting entries in <path>/etc/hosts</path>.</impo>

48

<note>It is recommended that you read this entire document and familiarize yourself with all the steps before attempting the install. If you run into problems with any of the steps, check the troubleshooting guide at the end of this document. Also, not all the referenced packages are necessary, this set up is very flexible. For instance, if you do not desire a web interface, feel free to skip the squirrelmail section.</note>

49

<note>It is recommended that you read this entire document and familiarize yourself with all the steps before attempting the install. If you run into problems with any of the steps, check the troubleshooting guide at the end of this document. Also, not all the referenced packages are necessary, this set up is very flexible. For instance, if you do not desire a web interface, feel free to skip the squirrelmail section.</note>

49

</body>

50

</body>

50

</chapter>

51

</chapter>

…

…

54

<pre caption="Install postfix" ># <i>emerge postfix</i>

55

<pre caption="Install postfix" ># <i>emerge postfix</i>

55

</pre>

56

</pre>

56

<warn>Verify that you have not installed any other MTA, such as ssmtp, exim, or qmail, or you will surely have BIG problems.</warn>

57

<warn>Verify that you have not installed any other MTA, such as ssmtp, exim, or qmail, or you will surely have BIG problems.</warn>

57

<p>After postfix is installed, it's time to configure it. Change the following options in <path>/etc/postfix/main.cf</path>:</p>

58

<p>After postfix is installed, it's time to configure it. Change the following options in <path>/etc/postfix/main.cf</path>:</p>

58

<pre caption="/etc/postfix/main.cf" >

59

<pre caption="/etc/postfix/main.cf" >

59

myhostname = $host.domain.name

60

myhostname = $host.domain.name

60

mydomain = $domain.name

61

mydomain = $domain.name

61

inet_interfaces = all

62

inet_interfaces = all

62

mydestination = $myhostname, localhost.$mydomain $mydomain

63

mydestination = $myhostname, localhost.$mydomain $mydomain

63

mynetworks = my.ip.net.work/24, 127.0.0.0/8

64

mynetworks = my.ip.net.work/24, 127.0.0.0/8

64

home_mailbox = .maildir/

65

home_mailbox = .maildir/

65

local_destination_concurrency_limit = 2

66

local_destination_concurrency_limit = 2

66

default_destination_concurrency_limit = 10 </pre>

67

default_destination_concurrency_limit = 10 </pre>

67

<p>Next change the following in <path>/etc/postfix/master.cf</path>. This will turn on verbose output for debugging:</p>

68

<p>Next change the following in <path>/etc/postfix/master.cf</path>. This will turn on verbose output for debugging:</p>

<codenote>Just add the <c>-v</c> after the smtpd in the above line</codenote>

76

<codenote>Just add the <c>-v</c> after the smtpd in the above line</codenote>

76

</pre>

77

</pre>

77

<p>Next, edit <path>/etc/mail/aliases</path> to add your local aliases. There should at least be an alias for root like: <c>root: your@email.address</c>.</p>

78

<p>Next, edit <path>/etc/mail/aliases</path> to add your local aliases. There should at least be an alias for root like: <c>root: your@email.address</c>.</p>

78

<pre caption="Starting postfix for the first time" >

79

<pre caption="Starting postfix for the first time" >

79

# <i>/usr/bin/newaliases</i>

80

# <i>/usr/bin/newaliases</i>

80

<codenote>This will install the new aliases. You only need to do this </codenote>

81

<codenote>This will install the new aliases. You only need to do this </codenote>

81

<codenote>when you update or install aliases.</codenote>

82

<codenote>when you update or install aliases.</codenote>

82

83

83

# <i>/etc/init.d/postfix start</i>

84

# <i>/etc/init.d/postfix start</i>

84

</pre>

85

</pre>

85

<p>Now that postfix is running, fire up your favorite console mail client and send yourself an email. I use <c>mutt</c> for all my console mail. Verify that postfix is delivering mail to local users, once that's done, we're on to the next step.</p>

86

<p>Now that postfix is running, fire up your favorite console mail client and send yourself an email. I use <c>mutt</c> for all my console mail. Verify that postfix is delivering mail to local users, once that's done, we're on to the next step.</p>

86

<note>I strongly recommend that you verify this basic postfix setup is functioning before you progress to the next step of the howto. </note>

87

<note>I strongly recommend that you verify this basic postfix setup is functioning before you progress to the next step of the howto. </note>

87

</body>

88

</body>

88

</chapter>

89

</chapter>

…

…

90

<title>Courier-imap</title>

91

<title>Courier-imap</title>

91

<body>

92

<body>

92

<pre caption="Install courier-imap" ># <i>emerge courier-imap</i>

93

<pre caption="Install courier-imap" ># <i>emerge courier-imap</i>

93

</pre>

94

</pre>

94

<pre caption="Courier-imap configuration" >

95

<pre caption="Courier-imap configuration" >

95

# <i>cd /etc/courier-imap</i>

96

# <i>cd /etc/courier-imap</i>

96

<codenote>If you want to use the ssl capabilities of courier-imap or pop3, </codenote>

97

<codenote>If you want to use the ssl capabilities of courier-imap or pop3, </codenote>

97

<codenote>you'll need to create certs for this purpose.</codenote>

98

<codenote>you'll need to create certs for this purpose.</codenote>

98

<codenote>This step is recommended. If you do not want to use ssl, skip this step.</codenote>

99

<codenote>This step is recommended. If you do not want to use ssl, skip this step.</codenote>

<p>Start up your favorite mail client and verify that all connections you've started work for receiving and sending mail. Now that the basics work, we're going to do a whole bunch of stuff at once to get the rest of the system running. Again, please verify that what we've installed already works before progressing.</p>

114

<p>Start up your favorite mail client and verify that all connections you've started work for receiving and sending mail. Now that the basics work, we're going to do a whole bunch of stuff at once to get the rest of the system running. Again, please verify that what we've installed already works before progressing.</p>

114

</body>

115

</body>

115

</chapter>

116

</chapter>

116

<chapter>

117

<chapter>

117

<title>Cyrus-sasl</title>

118

<title>Cyrus-sasl</title>

118

<body>

119

<body>

119

<p>Next we're going to install cyrus-sasl. Sasl is going to play the role of actually passing your auth variables to pam, which will in turn pass that information to mysql for authentication of smtp users. For this howto, we'll not even try to verify that sasl is working until mysql is set up and contains a test user. Which is fine since we'll be authenticating against mysql in the end anyway.</p>

120

<p>Next we're going to install cyrus-sasl. Sasl is going to play the role of actually passing your auth variables to pam, which will in turn pass that information to mysql for authentication of smtp users. For this howto, we'll not even try to verify that sasl is working until mysql is set up and contains a test user. Which is fine since we'll be authenticating against mysql in the end anyway.</p>

120

<note>Now for some reason, sasl will not play nicely with pam against the shadow file. I banged my head against this problem for, well, a long time. If anyone knows why sasl will not auth against the shadow file in its current gentoo incarnation, please <mail link="ken@kickasskungfu.com" >email me</mail> as I'd love to hear a solution to this.</note>

121

<note>Now for some reason, sasl will not play nicely with pam against the shadow file. I banged my head against this problem for, well, a long time. If anyone knows why sasl will not auth against the shadow file in its current gentoo incarnation, please <mail link="ken@kickasskungfu.com" >email me</mail> as I'd love to hear a solution to this.</note>

121

<p>Just to get sasl installed is going to require a bit of hacking. Open up the ebuild file and change the configure flags to disable digest and cram. Here's why: mail clients will try to authenticate against the <e>first</e> method presented to it, usually cram-md5. Since we're not going to set that up, cram authentication will fail and most clients will not by default try another method. This is mostly due to the way mail clients are currently put together. So we're going to disable auth methods we're not using in order to not confuse the clients out there.</p>

122

<pre caption="Configuring and installing the cyrus-sasl ebuild" >

122

<pre caption="Configuring and installing the cyrus-sasl ebuild" >

123

# <i>cd /usr/portage/dev-libs/cyrus-sasl</i>

124

# <i>nano -w cyrus-sasl.$currentversion.ebuild</i>

125

<codenote>Disable digest and cram as show below.</codenote>

126

127

econf \

128

--with-saslauthd=/var/lib/sasl2 \

129

--with-pwcheck=/var/lib/sasl2 \

130

--with-configdir=/etc/sasl2 \

131

--with-openssl \

132

--with-plugindir=/usr/lib/sasl2 \

133

--with-dbpath=/etc/sasl2/sasldb2 \

134

--with-des \

135

--with-rc4 \

136

--disable-krb4 \

137

--with-gnu-ld \

138

--enable-shared \

139

--disable-sample \

140

--enable-login \

141

--disable-cram \

142

--disable-digest \

143

${myconf} || die &quot;bad ./configure&quot;

144

145

# <i>USE='-ldap -mysql' emerge cyrus-sasl</i>

123

# <i>USE='-ldap -mysql' emerge cyrus-sasl</i>

146

<codenote>We don't have ldap and we're not using sasl's mysql capabilities </codenote>

124

<codenote>We don't have ldap and we're not using sasl's mysql capabilities </codenote>

147

<codenote>so we need to turn them off for this build.</codenote>

125

<codenote>so we need to turn them off for this build.</codenote>

148

</pre>

126

</pre>

149

<p>Next, edit <path>/var/lib/sasl2/smtp.conf</path>.</p>

127

<p>Next, edit <path>/usr/lib/sasl2/smtp.conf</path>.</p>

150

<pre caption="Starting sasl" >

128

<pre caption="Starting sasl" >

151

# <i>nano -w /var/lib/sasl2/smtp.conf</i>

129

# <i>nano -w /usr/lib/sasl2/smtp.conf</i>

152

pwcheck_method: saslauthd

130

pwcheck_method: saslauthd

153

131

mech_list: LOGIN PLAIN

132

<codenote>It's important to turn off auth mehtods we are not using.</codenote>

133

<codenote>They cause problems for some mail clients.</codenote>

154

# <i>/etc/init.d/saslauthd start</i>

134

# <i>/etc/init.d/saslauthd start</i>

155

</pre>

135

</pre>

156

</body>

136

</body>

157

</chapter>

137

</chapter>

158

<chapter>

138

<chapter>

159

<title>SSL Certs for Postfix and Apache</title>

139

<title>SSL Certs for Postfix and Apache</title>

160

<body>

140

<body>

161

<p>Next we're going to make a set of ssl certificates for postfix and apache.</p>

141

<p>Next we're going to make a set of ssl certificates for postfix and apache.</p>

162

<pre>

142

<pre>

163

# <i>cd /usr/lib/ssl/</i>

143

# <i>cd /etc/ssl/</i>

164

# <i>nano -w openssl.cnf</i>

144

# <i>nano -w openssl.cnf</i>

145

165

<codenote>Change the following default values for your domain:</codenote>

146

<codenote>Change the following default values for your domain:</codenote>

166

167

countryName_default

147

countryName_default

168

stateOrProvinceName_default

148

stateOrProvinceName_default

169

localityName_default

149

localityName_default

170

0.organizationName_default

150

0.organizationName_default

171

commonName_default

151

commonName_default

172

emailAddress_default.

152

emailAddress_default.

173

153

174

<codenote>If the variables are not already present, just add them in a sensible place.</codenote>

154

<codenote>If the variables are not already present, just add them in a sensible place.</codenote>

175

155

176

156

177

# <i>cd misc</i>

157

# <i>cd misc</i>

178

# <i>nano -w CA.pl</i>

158

# <i>nano -w CA.pl</i>

179

<codenote>We need to add -nodes to the # create a certificate and</codenote>

159

<codenote>We need to add -nodes to the # create a certificate and</codenote>

180

<codenote>#create a certificate request code in order to let our new ssl</codenote>

160

<codenote>#create a certificate request code in order to let our new ssl</codenote>

181

<codenote>certs be loaded without a password. Otherwise when you</codenote>

161

<codenote>certs be loaded without a password. Otherwise when you</codenote>

<codenote>smtpd_tls_auth_only is commented out to ease testing the system. </codenote>

222

<codenote>smtpd_tls_auth_only is commented out to ease testing the system. </codenote>

244

<codenote>You can turn this on later if you desire.</codenote>

223

<codenote>You can turn this on later if you desire.</codenote>

245

224

246

# <i>postfix reload</i>

225

# <i>postfix reload</i>

247

</pre>

226

</pre>

248

<p>Now we're going to verify that the config's we added were picked up by postfix.</p>

227

<p>Now we're going to verify that the config's we added were picked up by postfix.</p>

249

<pre caption="Verifying sasl and tls support" >

228

<pre caption="Verifying sasl and tls support" >

250

# <i>telnet localhost 25</i>

229

# <i>telnet localhost 25</i>

251

230

252

Trying 127.0.0.1...

231

Trying 127.0.0.1...

253

Connected to localhost.

232

Connected to localhost.

254

Escape character is '^]'.

233

Escape character is '^]'.

255

220 mail.domain.com ESMTP Postfix

234

220 mail.domain.com ESMTP Postfix

256

<i>EHLO domain.com</i>

235

<i>EHLO domain.com</i>

257

250-mail.domain.com

236

250-mail.domain.com

258

250-PIPELINING

237

250-PIPELINING

259

250-SIZE 10240000

238

250-SIZE 10240000

260

250-VRFY

239

250-VRFY

261

250-ETRN

240

250-ETRN

262

250-STARTTLS

241

250-STARTTLS

263

250-AUTH LOGIN PLAIN OTP

242

250-AUTH LOGIN PLAIN

264

250-AUTH=LOGIN PLAIN OTP

243

250-AUTH=LOGIN PLAIN

265

250-XVERP

244

250-XVERP

266

250 8BITMIME

245

250 8BITMIME

267

<i>^]</i>

246

<i>^]</i>

268

telnet> <i>quit</i>

247

telnet> <i>quit</i>

269

</pre>

248

</pre>

270

<p>Verify that the above AUTH and STARTTLS lines now appear in your postfix install. As I said before, as it stands now AUTH will not work. that's because sasl will try to auth against it's sasldb, instead of the shadow file for some unknown reason, which we have not set up. So we're going to just plow through and set up mysql to hold all of our auth and virtual domain information.

249

<p>Verify that the above AUTH and STARTTLS lines now appear in your postfix install. As I said before, as it stands now AUTH will not work. that's because sasl will try to auth against it's sasldb, instead of the shadow file for some unknown reason, which we have not set up. So we're going to just plow through and set up mysql to hold all of our auth and virtual domain information.

<p>Next we'll set up apache and add an interface to interact with the database more easily. </p>

317

<p>Next we'll set up apache and add an interface to interact with the database more easily. </p>

335

<pre caption="Setting up apache and phpmyadmin" >

318

<pre caption="Setting up apache and phpmyadmin" >

336

# <i>emerge apache mod_php mod_ssl phpmyadmin</i>

319

# <i>emerge apache mod_php mod_ssl phpmyadmin</i>

337

</pre>

320

</pre>

338

<p>There are plenty of guides out there about how to set up apache with php. Like this one: <uri>http://www.linuxguruz.org/z.php?id=31</uri>. There are also numerous posts on <uri>http://forums.gentoo.org</uri> detailing how to solve problems with the installation (search for 'apache php'). So, that said, I'm not going to cover it here. Set up the apache and php installs, then continue with this howto. Now, a word for the wise: .htaccess the directory that you put phpmyadmin in. If you do not do this, search engine spiders will come along and index the page which in turn will mean that anyone will be able to find your phpmyadmin page via google and in turn be able to come change your database however they want which is <e>BAD!</e> There are many howtos on this including: <uri>http://docs.csoft.net/micro/black-htaccess.html</uri>.</p>

321

<p>There are plenty of guides out there about how to set up apache with php. Like this one: <uri>http://www.linuxguruz.org/z.php?id=31</uri>. There are also numerous posts on <uri>http://forums.gentoo.org</uri> detailing how to solve problems with the installation (search for 'apache php'). So, that said, I'm not going to cover it here. Set up the apache and php installs, then continue with this howto. Now, a word for the wise: .htaccess the directory that you put phpmyadmin in. If you do not do this, search engine spiders will come along and index the page which in turn will mean that anyone will be able to find your phpmyadmin page via google and in turn be able to come change your database however they want which is <e>BAD!</e> There are many howtos on this including: <uri>http://docs.csoft.net/micro/black-htaccess.html</uri>.</p>

339

<p>Now we're going to install the Apache certificates we made previously. The Apache-SSL directives that you need to use the resulting cert are:

322

<p>Now we're going to install the Apache certificates we made previously. The Apache-SSL directives that you need to use the resulting cert are:

340

<ul>

323

<ul>

341

<li>SSLCertificateFile /path/to/certs/new.cert.cert</li>

324

<li>SSLCertificateFile /path/to/certs/new.cert.cert</li>

342

<li>SSLCertificateKeyFile /path/to/certs/new.cert.key</li>

325

<li>SSLCertificateKeyFile /path/to/certs/new.cert.key</li>

343

</ul>

326

</ul>

344

</p>

327

</p>

345

<pre caption="Install Apache SSL certificates" >

328

<pre caption="Install Apache SSL certificates" >

346

# <i>cp /usr/lib/ssl/misc/new.cert.cert /etc/apache/conf/ssl/</i>

329

# <i>cp /etc/ssl/misc/new.cert.cert /etc/apache/conf/ssl/</i>

347

# <i>cp /usr/lib/ssl/misc/new.cert.key /etc/apache/conf/ssl/</i>

330

# <i>cp /etc/ssl/misc/new.cert.key /etc/apache/conf/ssl/</i>

348

# <i>nano -w /etc/apache/conf/vhosts/ssl.default-vhost.conf</i>

331

# <i>nano -w /etc/apache/conf/vhosts/ssl.default-vhost.conf</i>

349

<codenote>Change the following parameters</codenote>

332

<codenote>Change the following parameters</codenote>

350

333

351

ServerName host.domain.name

334

ServerName host.domain.name

352

ServerAdmin your@email.address

335

ServerAdmin your@email.address

353

SSLCertificateFile /etc/apache/conf/ssl/new.cert.cert

336

SSLCertificateFile /etc/apache/conf/ssl/new.cert.cert

354

SSLCertificateKeyFile /etc/apache/conf/ssl/new.cert.key

337

SSLCertificateKeyFile /etc/apache/conf/ssl/new.cert.key

355

338

356

# <i>/etc/init.d/apache restart</i>

339

# <i>/etc/init.d/apache restart</i>

357

</pre>

340

</pre>

358

<note>If you have an existing apache install, you'll likely have to perform a full server reboot to install your new certificates. Check your logs to verify apache restarted successfully.</note>

341

<note>If you have an existing apache install, you'll likely have to perform a full server reboot to install your new certificates. Check your logs to verify apache restarted successfully.</note>

<p>Now enter the phpmyadmin page and browse the tables. You'll want to add in your local aliases, edit your user table to add a test user, and change your transport table to add information about your domains. The default values supplied with the dumpfile should be a sufficient guide to what values need to go where. Make sure that if you put information in the database that it is accurate. For instance, make sure the local users home dir exists and that the correct uid/gid values are in place. The maildirs should be created automatically by postfix when the user receives their first email. So, in general, it's a good idea to send a &quot;Welcome&quot; mail to a new user after you setup their account to make sure the .maildir gets created. </p>

355

<p>Now enter the phpmyadmin page and browse the tables. You'll want to add in your local aliases, edit your user table to add a test user, and change your transport table to add information about your domains. The default values supplied with the dumpfile should be a sufficient guide to what values need to go where. Make sure that if you put information in the database that it is accurate. For instance, make sure the local users home dir exists and that the correct uid/gid values are in place. The maildirs should be created automatically by postfix when the user receives their first email. So, in general, it's a good idea to send a &quot;Welcome&quot; mail to a new user after you setup their account to make sure the .maildir gets created. </p>

373

</body>

356

</body>

374

</chapter>

357

</chapter>

375

<chapter>

358

<chapter>

376

<title>The vmail user</title>

359

<title>The vmail user</title>

377

<body>

360

<body>

378

<p>At this point you may be wondering what user and directory to use for virtual mail users, and rightly so. Let's set that up.</p>

361

<p>At this point you may be wondering what user and directory to use for virtual mail users, and rightly so. Let's set that up.</p>

379

<pre caption="Adding the vmail user" >

362

<pre caption="Adding the vmail user" >

380

# <i>adduser -d /home/vmail -s /bin/false vmail</i>

363

# <i>adduser -d /home/vmail -s /bin/false vmail</i>

381

# <i>uid=`cat /etc/passwd | grep vmail | cut -f 3 -d :`</i>

364

# <i>uid=`cat /etc/passwd | grep vmail | cut -f 3 -d :`</i>

382

# <i>groupadd -g $uid vmail</i>

365

# <i>groupadd -g $uid vmail</i>

383

# <i>mkdir /home/vmail</i>

366

# <i>mkdir /home/vmail</i>

384

# <i>chown vmail. /home/vmail</i>

367

# <i>chown vmail. /home/vmail</i>

385

</pre>

368

</pre>

386

<p>So now when you're setting up vmail accounts, use the vmail uid, gid, and homedir. When you're setting up local accounts, use that users uid, gid, and homedir. We've been meaning to create a php admin page for this setup but haven't gotten around to it yet, as phpmyadmin generally works fine for us.</p>

369

<p>So now when you're setting up vmail accounts, use the vmail uid, gid, and homedir. When you're setting up local accounts, use that users uid, gid, and homedir. We've been meaning to create a php admin page for this setup but haven't gotten around to it yet, as phpmyadmin generally works fine for us.</p>

387

</body>

370

</body>

388

</chapter>

371

</chapter>

389

<chapter>

372

<chapter>

390

<title>Configuring MySQL Authentication and vhosts</title>

373

<title>Configuring MySQL Authentication and vhosts</title>

391

<body>

374

<body>

392

<p>Next we'll reconfigure our authentication to use the mailsql database in courier-imap and postfix. In all of the following examples, replace $password with the password you set for the mailsql mysql user.</p>

375

<p>Next we'll reconfigure our authentication to use the mailsql database in courier-imap and postfix. In all of the following examples, replace $password with the password you set for the mailsql mysql user.</p>

<p>As of Postfix 2.0.x, there were a number of significant changes over the 1.1.x release. Notably the transport, virtual-gid, and virtual-uid tables are no longer necessary. The tables are still included if you wish to use them.</p>

535

<p>As of Postfix 2.0.x, there were a number of significant changes over the 1.1.x release. Notably the transport, virtual-gid, and virtual-uid tables are no longer necessary. The tables are still included if you wish to use them.</p>

553

<note>It is recommended tha you read VIRTUAL_README included with the postfix doc's for more information.</note>

536

<note>It is recommended tha you read VIRTUAL_README included with the postfix doc's for more information.</note>

554

<pre># <i>postfix reload</i>

537

<pre># <i>postfix reload</i>

555

</pre>

538

</pre>

556

<p>Now, if all went well, you should have a functioning mailhost. Users should be able to authenticate against the sql database, using their full email address, for pop3, imap, and smtp. I would highly suggest that you verify that everything is working at this point. If you run into problems (with as many things as this setup has going on, it's likely that you will) check the troubleshooting section of this howto.</p>

539

<p>Now, if all went well, you should have a functioning mailhost. Users should be able to authenticate against the sql database, using their full email address, for pop3, imap, and smtp. I would highly suggest that you verify that everything is working at this point. If you run into problems (with as many things as this setup has going on, it's likely that you will) check the troubleshooting section of this howto.</p>

…

…

558

</chapter>

541

</chapter>

559

<chapter>

542

<chapter>

560

<title>Squirrelmail</title>

543

<title>Squirrelmail</title>

561

<body>

544

<body>

562

<pre>

545

<pre>

563

# <i>emerge squirrelmail</i>

546

# <i>emerge squirrelmail</i>

564

<codenote>I like to add a link to the htdocs space for a shorter url.</codenote>

547

<codenote>I like to add a link to the htdocs space for a shorter url.</codenote>

<codenote>Now you should be able to login to squirrelmail, again - with your full email address,</codenote>

553

<codenote>Now you should be able to login to squirrelmail, again - with your full email address,</codenote>

571

<codenote>and use your new webmail setup.</codenote>

554

<codenote>and use your new webmail setup.</codenote>

572

</pre>

555

</pre>

573

</body>

556

</body>

574

</chapter>

557

</chapter>

575

<chapter>

558

<chapter>

576

<title>Mailman</title>

559

<title>Mailman</title>

577

<body>

560

<body>

578

<p>Last step: mailman. The new version of mailman has very nice virtual domain support, which is why I use it, not to mention it's really a great package. To get this package installed and working correclty for virtual domains is going to require a bit of hacking. I really reccommend reading all of the mailman documentation, including README.POSTFIX.gz, to understand what's being done here.</p>

561

<p>Last step: mailman. The new version of mailman has very nice virtual domain support, which is why I use it, not to mention it's really a great package. To get this package installed and working correctly for virtual domains is going to require a bit of hacking. I really recommend reading all of the mailman documentation, including README.POSTFIX.gz, to understand what's being done here.</p>

562

<p>One further note, current versions of mailman install to /usr/local/mailman. If you're like me and wish to change the default install location, it can be overridden in the ebuild filoe by changing the INSTALLDIR variable.</p>

579

<pre caption="/usr/portage/net-mail/mailman/mailman-$ver.ebuild">

563

<pre caption="/usr/portage/net-mail/mailman/mailman-$ver.ebuild">

580

# <i>nano -w /usr/portage/net-mail/mailman/mailman-$ver.ebuild</i>

564

# <i>nano -w /usr/portage/net-mail/mailman/mailman-$ver.ebuild</i>

581

MAILGID="280"

565

MAILGID="280"

582

<codenote>Set MAILGID to the mailman group instead of nobody</codenote>

566

<codenote>Set MAILGID to the mailman group instead of nobody</codenote>

583

<codenote>This is needed for postfix integration</codenote>

567

<codenote>This is needed for postfix integration</codenote>

584

</pre>

585

<pre>

568

</pre>

569

<pre>

586

# <i>emerge mailman</i>

570

# <i>emerge mailman</i>

587

<codenote>This package is currently masked as well, so you'll need to unmask it or give </codenote>

571

<codenote>This package is currently masked as well, so you'll need to unmask it or give </codenote>

588

<codenote>emerge an explicit path to the ebuild. Once it's installed, follow the directions</codenote>

572

<codenote>emerge an explicit path to the ebuild. Once it's installed, follow the directions</codenote>

589

<codenote>in the README.gentoo.gz</codenote>

573

<codenote>in the README.gentoo.gz *except* do not add your aliases to /etc/mail/aliases.</codenote>

574

<codenote>We will instead be linking the entire alias db into postfix.</codenote>

590

575

591

# <i>nano -w /usr/share/doc/mailman-$ver/README.gentoo.gz</i>

576

# <i>zless /usr/share/doc/mailman-$ver/README.gentoo.gz</i>

577

</pre>

578

<pre caption="Setting defaults: Mailman/Defaults.py">

579

# <i> nano -w /var/mailman/Mailman/Defaults.py</i>

580

<codenote>Change the values below to reflect your primary domain, virtuals will be set next.</codenote>

<p> You should now be able to setup mailing lists for any domain on your box. Last note on this, make sure you run all mailman commands as the user mailman (<c>su mailman</c>) or else the permissions will be wrong and you'll have to fix them. Read the mailman doc's for more information on setting up and managing mailman lists.</p>

646

<p> You should now be able to setup mailing lists for any domain on your box. Last note on this, make sure you run all mailman commands as the user mailman (<c>su mailman</c>) or else the permissions will be wrong and you'll have to fix them. Read the mailman doc's for more information on setting up and managing mailman lists.</p>

654

</body>

647

</body>

655

</chapter>

648

</chapter>

656

<chapter>

649

<chapter>

657

<title>Content Filtering and Anti-Virus</title>

650

<title>Content Filtering and Anti-Virus</title>

658

<body><p>Coming soon...</p></body>

651

<body><p>Coming soon...it would be done already but I need some perl help and testing to make it so. If you'd like to volunteer for that, please email me.</p></body>

659

</chapter>

652

</chapter>

660

<chapter>

653

<chapter>

661

<title>Wrap Up</title>

654

<title>Wrap Up</title>

662

<body>

655

<body>

663

<p>Ok, you're all set, edit <path>/etc/postfix/master.cf</path> and turn off verbose mode for production use. You'll probably also want to add the services to your startup routine to make sure everything comes back up on a reboot. Make sure to add all the services you're using - apache, mysql, saslauthd, postfix, courier-imapd, courier-imapd-ssl, courier-pop3d, and courier-pop3d-ssl are all up to your decision on what access you want to provide. I generally have all the services enabled.</p>

656

<p>Ok, you're all set, edit <path>/etc/postfix/master.cf</path> and turn off verbose mode for production use. You'll probably also want to add the services to your startup routine to make sure everything comes back up on a reboot. Make sure to add all the services you're using - apache, mysql, saslauthd, postfix, courier-imapd, courier-imapd-ssl, courier-pop3d, and courier-pop3d-ssl are all up to your decision on what access you want to provide. I generally have all the services enabled.</p>

664

<pre caption="Wrap up" >

657

<pre caption="Wrap up" >

665

# <i>postfix reload</i>

658

# <i>postfix reload</i>

666

# <i>rc-update add $service default</i>

659

# <i>rc-update add $service default</i>

667

</pre>

660

</pre>

668

<p>

661

<p>

669

<e>Have fun!</e>

662

<e>Have fun!</e>

670

</p>

663

</p>

671

</body>

664

</body>

…

…

681

<section>

674

<section>

682

<title>Step 1: Check your config files.</title>

675

<title>Step 1: Check your config files.</title>

683

<body>

676

<body>

684

<p>Typos are killers, especially when dealing with authentication systems. Scan your config's and mailsql database for typo's. You can debug all you want, but if you're not passing the right information back and forth to your mail system, it's not going to work. If you make a change to a config file for a service, make sure you restart that service so that the config change gets picked up.</p>

677

<p>Typos are killers, especially when dealing with authentication systems. Scan your config's and mailsql database for typo's. You can debug all you want, but if you're not passing the right information back and forth to your mail system, it's not going to work. If you make a change to a config file for a service, make sure you restart that service so that the config change gets picked up.</p>

685

<pre>

678

<pre>

686

# <i>/etc/init.d/service restart</i>

679

# <i>/etc/init.d/service restart</i>

687

</pre>

680

</pre>

688

</body>

681

</body>

689

</section>

682

</section>

690

<section>

683

<section>

691

<title>Step 2: Are all the necessary services actually running?</title>

684

<title>Step 2: Are all the necessary services actually running?</title>

692

<body>

685

<body>

693

<p>If it's not running, start it up. It's awful hard to debug a service that isn't running. Sometimes a service will act like it's started but still not function. Sometimes, when a bad config is used, or a bad transmission comes into a mail component, the service will hang and keep the port from being used by another process. Sometimes you can detect this with netstat. Or, if you've been at it awhile, just take a break and reboot your box in the meantime. That will clear out any hung services. Then you can come back fresh and try it again.</p>

686

<p>If it's not running, start it up. It's awful hard to debug a service that isn't running. Sometimes a service will act like it's started but still not function. Sometimes, when a bad config is used, or a bad transmission comes into a mail component, the service will hang and keep the port from being used by another process. Sometimes you can detect this with netstat. Or, if you've been at it awhile, just take a break and reboot your box in the meantime. That will clear out any hung services. Then you can come back fresh and try it again.</p>

694

<pre>

687

<pre>

695

# <i>/etc/init.d/$service status</i>

688

# <i>/etc/init.d/$service status</i>

696

# <i>netstat -a | grep $service (or $port)</i>

689

# <i>netstat -a | grep $service (or $port)</i>

697

</pre>

690

</pre>

698

</body>

691

</body>

699

</section>

692

</section>

700

<section>

693

<section>

701

<title>Step 3: Are all the service using the current config's?</title>

694

<title>Step 3: Are all the service using the current config's?</title>

702

<body>

695

<body>

703

<p>If you've recently made a change to a config file, restart that service to make sure it's using the current version. Some of the components will dump their current config's to you, like postfix.</p>

696

<p>If you've recently made a change to a config file, restart that service to make sure it's using the current version. Some of the components will dump their current config's to you, like postfix.</p>

<p>Repeat after me, logs are my friend. My next troubleshooting stop is always the logs. Sometimes it's helpful to try a failed operation again then check the logs so that the error message is right at the bottom (or top depending on your logger) instead of buried in there somewhere. See if there is any information in your log that can help you diagnose the problem, or at the very least, figure out which component is having the problem.</p>

708

<p>Repeat after me, logs are my friend. My next troubleshooting stop is always the logs. Sometimes it's helpful to try a failed operation again then check the logs so that the error message is right at the bottom (or top depending on your logger) instead of buried in there somewhere. See if there is any information in your log that can help you diagnose the problem, or at the very least, figure out which component is having the problem.</p>

<p>You may also find the debug_peer parameters in main.cf helpful. Setting these will increase log output over just verbose mode.</p>

715

<p>You may also find the debug_peer parameters in main.cf helpful. Setting these will increase log output over just verbose mode.</p>

723

<pre caption="adding debug_peer support">

716

<pre caption="adding debug_peer support">

724

# <i>nano -w /etc/postfix/main.cf</i>

717

# <i>nano -w /etc/postfix/main.cf</i>

725

debug_peer_level = 5

718

debug_peer_level = 5

726

debug_peer_list = $host.domain.name

719

debug_peer_list = $host.domain.name

727

<codenote>Uncomment one of the suggested debugger</codenote>

720

<codenote>Uncomment one of the suggested debugger</codenote>

728

<codenote>commands as well.</codenote>

721

<codenote>commands as well.</codenote>

729

</pre>

722

</pre>

730

</body>

723

</body>

731

</section>

724

</section>

732

<section>

725

<section>

733

<title>Step 5: Talk to the service itself.</title>

726

<title>Step 5: Talk to the service itself.</title>

734

<body>

727

<body>

735

<p>SMTP, IMAP, and POP3 all respond to telnet sessions. As we've seen earlier when we verified postfix's config. Sometimes it's helpful to open a telnet session to the service itself and see what's happening.</p>

728

<p>SMTP, IMAP, and POP3 all respond to telnet sessions. As we've seen earlier when we verified postfix's config. Sometimes it's helpful to open a telnet session to the service itself and see what's happening.</p>

736

<pre>

729

<pre>

737

# <i>telnet localhost $port</i>

730

# <i>telnet localhost $port</i>

738

<codenote>SMTP is 25, IMAP is 143, POP3 is 110. You should receive at least an OK string,</codenote>

731

<codenote>SMTP is 25, IMAP is 143, POP3 is 110. You should receive at least an OK string,</codenote>

739

<codenote>letting you know that the service is running and ready to respond to requests.</codenote>

732

<codenote>letting you know that the service is running and ready to respond to requests.</codenote>

<title>Step 6: Sometimes only the big guns will give you the information you need: strace.</title>

742

<title>Step 6: Sometimes only the big guns will give you the information you need: strace.</title>

750

<body>

743

<body>

751

<p>You should have this installed anyway. This is an invaluable tool for debugging software. You can start commands from the command line with strace and watch all the system calls as they happen. It often dumps a huge amount of information, so you'll either need to watch it realtime as you retry a failed transaction with the mail system, or dump the output to a file for review.</p>

744

<p>You should have this installed anyway. This is an invaluable tool for debugging software. You can start commands from the command line with strace and watch all the system calls as they happen. It often dumps a huge amount of information, so you'll either need to watch it realtime as you retry a failed transaction with the mail system, or dump the output to a file for review.</p>