Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (Debian Lenny) - Page 4

12 Test Postfix

To see if Postfix is ready for SMTP-AUTH and TLS, run

telnet localhost 25

After you have established the connection to your Postfix mail server type

ehlo localhost

If you see the lines

250-STARTTLS

and

250-AUTH LOGIN PLAIN

everything is fine:

server1:~# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 server1.example.com ESMTP Postfix (Debian/GNU)
ehlo localhost
250-server1.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.
server1:~#

Type

quit

to return to the system shell.

 

13 Populate The Database And Test

To populate the database you can use the MySQL shell:

mysql -u root -p

USE mail;

At least you have to create entries in the tables domains and users:

INSERT INTO `domains` (`domain`) VALUES ('example.com');
INSERT INTO `users` (`email`, `password`, `quota`) VALUES ('[email protected]', ENCRYPT('secret'), 10485760);

(Please take care that you use the ENCRYPT syntax in the second INSERT statement in order to encrypt the password!)

If you want to make entries in the other two tables, that would look like this:

INSERT INTO `forwardings` (`source`, `destination`) VALUES ('[email protected]', '[email protected]');
INSERT INTO `transport` (`domain`, `transport`) VALUES ('example.com', 'smtp:mail.example.com');

To leave the MySQL shell, type

quit;

For most people it is easier if they have a graphical front-end to MySQL; therefore you can also use phpMyAdmin (in this example under http://192.168.0.100/phpmyadmin/ or http://server1.example.com/phpmyadmin/) to administrate the mail database. Again, when you create a user, go sure that you use the ENCRYPT function to encrypt the password:

I do not think I have to explain the domains and users table further.

The forwardings table can have entries like the following:

source destination  
[email protected] [email protected] Redirects emails for [email protected] to [email protected]
@example.com [email protected] Creates a Catch-All account for [email protected] All emails to example.com will arrive at [email protected], except those that exist in the users table (i.e., if [email protected] exists in the users table, mails to [email protected] will still arrive at [email protected]).
@example.com @anotherdomain.tld This redirects all emails to example.com to the same user at anotherdomain.tld. E.g., emails to [email protected] will be forwarded to [email protected]
[email protected] [email protected], [email protected] Forward emails for [email protected] to two or more email addresses. All listed email addresses under destination receive a copy of the email.

The transport table can have entries like these:

domain transport  
example.com : Delivers emails for example.com locally. This is as if this record would not exist in this table at all.
example.com smtp:mail.anotherdomain.tld Delivers all emails for example.com via smtp to the server mail.anotherdomain.com.
example.com smtp:mail.anotherdomain.tld:2025 Delivers all emails for example.com via smtp to the server mail.anotherdomain.com, but on port 2025, not 25 which is the default port for smtp.
example.com

smtp:[1.2.3.4]
smtp:[1.2.3.4]:2025
smtp:[mail.anotherdomain.tld]

The square brackets prevent Postfix from doing lookups of the MX DNS record for the address in square brackets. Makes sense for IP addresses.
.example.com smtp:mail.anotherdomain.tld Mail for any subdomain of example.com is delivered to mail.anotherdomain.tld.
* smtp:mail.anotherdomain.tld All emails are delivered to mail.anotherdomain.tld.
[email protected] smtp:mail.anotherdomain.tld Emails for [email protected] are delivered to mail.anotherdomain.tld.

See

man transport

for more details.

Please keep in mind that the order of entries in the transport table is important! The entries will be followed from the top to the bottom.

Important: Postfix uses a caching mechanism for the transports, therefore it might take a while until you changes in the transport table take effect. If you want them to take effect immediately, run

postfix reload

after you have made your changes in the transport table.

 

14 Send A Welcome Email For Creating Maildir

When you create a new email account and try to fetch emails from it (with POP3/IMAP) you will probably get error messages saying that the Maildir doesn't exist. The Maildir is created automatically when the first email arrives for the new account. Therefore it's a good idea to send a welcome email to a new account.

First, we install the mailx package:

apt-get install mailx

To send a welcome email to [email protected], we do this:

mailx [email protected]

You will be prompted for the subject. Type in the subject (e.g. Welcome), then press ENTER, and in the next line type your message. When the message is finished, press ENTER again so that you are in a new line, then press CTRL+D; if you don't want to cc the mail, press ENTER again:

root@server1:/usr/local/sbin# mailx [email protected]
Subject: Welcome
<-- ENTER
Welcome! Have fun with your new mail account. <-- ENTER
<-- CTRL+D
Cc: <-- ENTER
root@server1:/usr/local/sbin#

Share this page:

7 Comment(s)

Add comment

Comments

From: Anonymous at: 2009-05-01 07:24:00

Hi, is it possible to put more than 1 address in field "destination" of  forwardings table? it doesn't seem to work. Can you help me?

 Very good work! thk

 

 

From: Anonymous at: 2009-09-15 07:43:25

You don't add several to the destination, you just insert a second row with all fields the same, but the destination differing.

 

from/to:

[email protected]/[email protected]

[email protected]/[email protected]

 

If, for example, only the destination differs, you still insert a row for each unique forwarding.

 

Tim

From: Karolis Tamutis at: 2010-01-04 20:35:33

Please save yourself some frustration and know that passwords encrypted with crypt are salted, up to 8 characters long.

You may enter 9+ char password into PMA which would discard everything after 8th char, this can lead to some weird scenarions, like users being able to authenticate with other users passwords (which match up to 8 first chars).

In short: be aware of the 8 char limit, users with MySQL setup passwords such as 123456781 and 123456782 will be able to authenticate with either password.

From: at: 2010-02-01 14:42:16

If I setup as a local user an email like [email protected] then when I want to send an email to [email protected], postfix will try to send that email locally, because match gmail.com in mail_domains and it think that that is an internal email...

 Any idea how to solve this problem?

 

Thanks

MiK

From: Anonymous2 at: 2010-02-24 23:39:56

Hey!

When I try to send an email from yahoo/google to the email account which I inserted into the databases, the email isn't delivered.

The mail from yahoo says:

 [email protected]: unknown user: test


From: tomiC at: 2010-09-30 14:57:03

When i try to start postfix /etc/init.d/postfix restart i get the following message in the mail.log

fatal: /etc/postfix/master.cf: line 83: missing "transport type" field

What's the problem?

regards

From: Pete at: 2011-03-08 01:46:54

This is a superb tutorial, I learnt so much from it, and best of all, it works!  Thanks very much for all your time and effort.