Prerequisite knowledge for configuring settings described in this post:
Postfix configuration parameters are controlled via the main.cf file, located at /var/postfix/main.cf
Postfix differentiates between three different sorts of domains:
- Local users (normal system users, as listed in the /etc/passwd file): It’s not possible to make local users work in just one domain. They will rather receive (and save under /var/mail/USERNAME) email sent to any and all local domains, ie all domains in the mydestination configuration setting. (The mydestination parameter specifies what domains this machine will deliver locally, instead of forwarding to another machine. eg mydestination = example.org, example.com, example.net) Takeaway message: All system users will get emails send to their_username@ any local domain.
- Virtual mailbox domains/virtual users: These are also domains you specify in your Postfix configuration settings as ones that will be used to receive email (in this case using the virtual_mailbox_domains = example.org example.com), but rather than using system users (/etc/passwd) to specify valid email addresses in that domain, you explicitly tell Postfix in its config settings which addresses are valid in a domain. You then specify similarly which emails we are ready to receive emails for and where they’ll be stored on the disk.
- Virtual alias domains: These are used to forward email from one email address to another. They can’t receive email, only forward it to somewhere else, or to several someplace elses.
If you have very few domains, the domains can be specified directly in the config file and the emails in a text file. See here for more info, but basically the text file is a mapping file, that is, it contains two columns.
For larger setups, these textfiles can be configured with information on how to connect to the same two columns’ worth of data as stored in your MySQL server instead.
After you’ve finished specifying your configurations, you need to run the postmap tool on the files to compile them.
Assuming a properly configured setup, users can be entered at the SQL command line like so:
INSERT INTO `mail`.`users` (`email`, `password`, `quota`) VALUES ('firstname.lastname@example.org', ENCRYPT('secret'), 1073741824);
The folder structure for any given email address isn’t set up until an email is received at that address, so shoot a test email through before checking to see if you can log in via your SquirrelMail or other webmail.
If you find you can’t log in, and want to check whether the email’s been received, you can search the logs for instances of your new email address:
To move to the end of the log file (where your activity will be, unless you slipped into a decent sleep after dispatching your test email):
To search the file you need to type a / then the words you want to search on:
Press ‘esc’ to cancel out of searching, (little) ‘n’ to jump forward through the instances of your search term that were found in the log, and (capital) ‘N’ to search backwards.
If the only thing you’re finding is failed login attempts and no record of your test email having been received, keep a-waiting, all’s probably well and the test email just hasn’t arrived yet. When it does you’ll be able to log in successfully.
Resources Referred To:
- Virtual Domains (The three Postfix domain types)
- Basic Configuration: Postfix Configuration Parameters
- Setting up a mail server using Postfix in five minutes
- Postfix MySQL How-to
- Email with Postfix, Dovecot, and MySQL
- How-To: Virtual Emails Accounts With Postfix And Dovecot