特殊:Badtitle/NS100:PostfixBasicSetupHowto:修订间差异
小 New page: {{From|https://help.ubuntu.com/community/PostfixBasicSetupHowto}} {{Languages|php5}} == Introduction == This document will teach you how to set up a basic Postfix mail server with IMAP... |
小无编辑摘要 |
||
(未显示2个用户的11个中间版本) | |||
第1行: | 第1行: | ||
{{From|https://help.ubuntu.com/community/PostfixBasicSetupHowto}} | {{From|https://help.ubuntu.com/community/PostfixBasicSetupHowto}} | ||
{{Languages| | {{Languages|UbuntuHelp:PostfixBasicSetupHowto}} | ||
== Introduction == | == Introduction == | ||
This document will teach you how to set up a basic Postfix mail server with IMAP and POP3 services. It does not included advanced topics such as integrating virus-checking and spam-filtering, which are dealt with in [[UbuntuHelp:PostfixVirtualMailBoxClamSmtpHowto|PostfixVirtualMailBoxClamSmtpHowto]] and [[UbuntuHelp:PostfixCompleteVirtualMailSystemHowto|PostfixCompleteVirtualMailSystemHowto]]. | |||
This document will teach you how to set up a basic Postfix mail server with IMAP and POP3 services. It does not included advanced topics such as integrating virus-checking and spam-filtering, which are dealt with in PostfixVirtualMailBoxClamSmtpHowto and PostfixCompleteVirtualMailSystemHowto. | |||
== Setup Overview == | == Setup Overview == | ||
In our setup, Postfix sends and receives mail from Internet and stores them in the user mailboxes while clients on the Internet can retrieve their mails via Courier IMAP or POP3. The user authentication is done by Courier Authdaemon. The following diagram shows this process. | |||
In our setup, Postfix sends and receives mail from Internet and stores them in the user mailboxes while clients | '''https://help.ubuntu.com/community/PostfixBasicSetupHowto?action=AttachFile&do=get&target=SetupOverview.jpg''' | ||
''' | |||
== Anatomy of Postfix == | == Anatomy of Postfix == | ||
=== Components === | === Components === | ||
The following figure shows the main Postfix system components, and the main information flows between them. | |||
The | '''https://help.ubuntu.com/community/PostfixBasicSetupHowto?action=AttachFile&do=get&target=PostfixComponentsNw.gif''' | ||
''' | |||
* Yellow ellipsoids are mail programs. | * Yellow ellipsoids are mail programs. | ||
* Yellow boxes are mail queues or files. | * Yellow boxes are mail queues or files. | ||
* Blue boxes are lookup tables. | * Blue boxes are lookup tables. | ||
* Programs in the large box run under control by the Postfix resident master daemon. | * Programs in the large box run under control by the Postfix resident master daemon. | ||
* Data in the large box is property of the Postfix mail system. | * Data in the large box is property of the Postfix mail system. | ||
=== Receiving Mail === | === Receiving Mail === | ||
When a message enters the Postfix mail system, the first stop is the incoming queue. The figure below shows the main components that are involved with new mail. | |||
When a message enters the Postfix mail system, the first stop | '''https://help.ubuntu.com/community/PostfixBasicSetupHowto?action=AttachFile&do=get&target=PosfixRecieving.gif''' | ||
''' | |||
* Mail is posted locally. The Postfix [http://www.postfix.org/sendmail.1.html sendmail] program invokes the privileged [http://www.postfix.org/postdrop.1.html postdrop] program which deposits the message into the '''maildrop''' directory, where the message is picked up by the [http://www.postfix.org/pickup.8.html pickup] daemon. This daemon does some sanity checks, in order to protect the rest of the Postfix system. | * Mail is posted locally. The Postfix [http://www.postfix.org/sendmail.1.html sendmail] program invokes the privileged [http://www.postfix.org/postdrop.1.html postdrop] program which deposits the message into the '''maildrop''' directory, where the message is picked up by the [http://www.postfix.org/pickup.8.html pickup] daemon. This daemon does some sanity checks, in order to protect the rest of the Postfix system. | ||
* Mail comes in via the network. The Postfix [http://www.postfix.org/smtpd.8.html SMTP server] receives the message and does some sanity checks, in order to protect the rest of the Postfix system. | |||
* Mail comes in via the network. The Postfix [http://www.postfix.org/smtpd.8.html SMTP server] receives the message and does some sanity checks, in order to protect the rest of the Postfix system. | |||
* Mail is generated internally by the Postfix system itself, in order to return undeliverable mail to the sender. The [http://www.postfix.org/bounce.8.html bounce or defer] daemon brings the bad news. | * Mail is generated internally by the Postfix system itself, in order to return undeliverable mail to the sender. The [http://www.postfix.org/bounce.8.html bounce or defer] daemon brings the bad news. | ||
* Mail is forwarded by the [http://www.postfix.org/local.8.html local] delivery agent, either via an entry in the system-wide [http://www.postfix.org/aliases.5.html alias] database, or via an entry in a per-user [http://www.postfix.org/aliases.5.html .forward] file. This is indicated with the unlabeled arrow. | * Mail is forwarded by the [http://www.postfix.org/local.8.html local] delivery agent, either via an entry in the system-wide [http://www.postfix.org/aliases.5.html alias] database, or via an entry in a per-user [http://www.postfix.org/aliases.5.html .forward] file. This is indicated with the unlabeled arrow. | ||
* Mail is generated internally by the Postfix system itself, in order to [http://www.postfix.org/basic.html#notify notify] the postmaster of a problem (this path is also indicated with the unlabeled arrow).The Postfix system can be configured to notify the postmaster of SMTP protocol problems, [http://en.wikipedia.org/wiki/E-mail_spam UCE] policy violations, and so on. | * Mail is generated internally by the Postfix system itself, in order to [http://www.postfix.org/basic.html#notify notify] the postmaster of a problem (this path is also indicated with the unlabeled arrow).The Postfix system can be configured to notify the postmaster of SMTP protocol problems, [http://en.wikipedia.org/wiki/E-mail_spam UCE] policy violations, and so on. | ||
* The [http://www.postfix.org/cleanup.8.html cleanup] daemon implements the final processing stage for new mail. It adds missing '''From:''' and other message headers, arranges for address rewriting to the standard [email protected] form, and optionally extracts recipient addresses from message headers. The '''cleanup''' daemon inserts the result as a single queue file into the '''incoming''' queue, and notifies the [http://www.postfix.org/qmgr.8.html queue manager] of the arrival of new mail. The '''cleanup''' daemon can be configured to transform addresses on the basis of [http://www.postfix.org/rewrite.html#canonical canonical] and [http://www.postfix.org/rewrite.html#virtual virtua] table lookups. | * The [http://www.postfix.org/cleanup.8.html cleanup] daemon implements the final processing stage for new mail. It adds missing '''From:''' and other message headers, arranges for address rewriting to the standard [email protected] form, and optionally extracts recipient addresses from message headers. The '''cleanup''' daemon inserts the result as a single queue file into the '''incoming''' queue, and notifies the [http://www.postfix.org/qmgr.8.html queue manager] of the arrival of new mail. The '''cleanup''' daemon can be configured to transform addresses on the basis of [http://www.postfix.org/rewrite.html#canonical canonical] and [http://www.postfix.org/rewrite.html#virtual virtua] table lookups. | ||
* On request by the cleanup daemon, the [http://www.postfix.org/trivial-rewrite.8.html trivial-rewrite] daemon rewrites addresses to the standard [email protected] form. | * On request by the cleanup daemon, the [http://www.postfix.org/trivial-rewrite.8.html trivial-rewrite] daemon rewrites addresses to the standard [email protected] form. | ||
== Install Postfix == | == Install Postfix == | ||
In this setup I assume that your domain is <code><nowiki>yourdomain.com</nowiki></code> and it has a valid MX record setup as <code><nowiki>mail.yourdomain.com</nowiki></code>. Remember to replace <code><nowiki>yourdomain.com</nowiki></code> with your actual domain in the example codes in this howto. Also I assume that you know what an MX record is. To find out MX your type in a terminal: | |||
In this setup I assume that your domain is <code><nowiki>yourdomain.com</nowiki></code> and it has a valid MX record | |||
<pre><nowiki> | <pre><nowiki> | ||
dig mx yourdomain.com | dig mx yourdomain.com | ||
</nowiki></pre> | </nowiki></pre> | ||
'''To install postfix''' | '''To install postfix''' | ||
<pre><nowiki> | |||
<pre><nowiki> | |||
sudo apt-get install postfix | sudo apt-get install postfix | ||
</nowiki></pre> | </nowiki></pre> | ||
Intall mailx package for use as command mail utility program. Mail command is installed with this package. | Intall mailx package for use as command mail utility program. Mail command is installed with this package. | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo apt-get install mailx | sudo apt-get install mailx | ||
</nowiki></pre> | </nowiki></pre> | ||
== Test your default setup == | == Test your default setup == | ||
Add a user before you start this. | Add a user before you start this. | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo useradd -m -s /bin/bash fmaster | sudo useradd -m -s /bin/bash fmaster | ||
sudo passwd fmaster | sudo passwd fmaster | ||
</nowiki></pre> | </nowiki></pre> | ||
Test your default installation using the following code segment. | |||
Test your default installation using the following code segment. | |||
<pre><nowiki> | <pre><nowiki> | ||
netcat localhost 25 | |||
</nowiki></pre> | </nowiki></pre> | ||
Postfix will prompt like following in the terminal so that you can use to type SMTP commands. | Postfix will prompt like following in the terminal so that you can use to type SMTP commands. | ||
<pre><nowiki> | <pre><nowiki> | ||
Trying 127.0.0.1... | Trying 127.0.0.1... | ||
第92行: | 第55行: | ||
220 localhost.localdomain ESMTP Postfix (Ubuntu) | 220 localhost.localdomain ESMTP Postfix (Ubuntu) | ||
</nowiki></pre> | </nowiki></pre> | ||
Type the following code segment in Postfix's prompt. | Type the following code segment in Postfix's prompt. | ||
<pre><nowiki> | <pre><nowiki> | ||
ehlo localhost | ehlo localhost | ||
第100行: | 第61行: | ||
rcpt to: fmaster@localhost | rcpt to: fmaster@localhost | ||
data | data | ||
Subject: My first mail on Postfix | |||
Hi, | Hi, | ||
Are you there? | Are you there? | ||
第106行: | 第68行: | ||
Admin | Admin | ||
. (Type the .[dot] in a new Line and press Enter ) | . (Type the .[dot] in a new Line and press Enter ) | ||
quit | quit | ||
</nowiki></pre> | </nowiki></pre> | ||
Check the mailbox of <code><nowiki>fmaster</nowiki></code> | Check the mailbox of <code><nowiki>fmaster</nowiki></code> | ||
<pre><nowiki> | <pre><nowiki> | ||
su - fmaster | su - fmaster | ||
mail | mail | ||
</nowiki></pre> | </nowiki></pre> | ||
When you type <code><nowiki>mail</nowiki></code> command an output like follows display in your terminal. | |||
When | |||
<pre><nowiki> | <pre><nowiki> | ||
Mail version 8.1.2 01/15/2001. Type ? for help. | Mail version 8.1.2 01/15/2001. Type ? for help. | ||
第125行: | 第83行: | ||
& | & | ||
</nowiki></pre> | </nowiki></pre> | ||
You will observe that mails are indexed by numbers and you can type the number of which the mail that you want to read. For example type no <code><nowiki>"2"</nowiki></code> to read the 2nd mail. The type <code><nowiki>"q"</nowiki></code> to quit. The mail will be written to a file called <code><nowiki>mbox</nowiki></code> in user's home directory. According to our example it will be <code><nowiki>/home/fmaster/mbox</nowiki></code>. | You will observe that mails are indexed by numbers and you can type the number of which the mail that you want to read. For example type no <code><nowiki>"2"</nowiki></code> to read the 2nd mail. The type <code><nowiki>"q"</nowiki></code> to quit. The mail will be written to a file called <code><nowiki>mbox</nowiki></code> in user's home directory. According to our example it will be <code><nowiki>/home/fmaster/mbox</nowiki></code>. | ||
All messages in an mbox type of mailbox are concatenated and stored in a single file. The beginning of each message is indicated by a line whose first five characters are "From " and a blank line is appended to the end of each message | All messages in an mbox type of mailbox are concatenated and stored in a single file. The beginning of each message is indicated by a line whose first five characters are "From " and a blank line is appended to the end of each message | ||
== Setting Postfix Support for Maildir-style Mailboxes == | == Setting Postfix Support for Maildir-style Mailboxes == | ||
Maildir is a format for an e-mail spool that does not require file locking to maintain message integrity because the messages are kept in separate files with unique names. A Maildir is a directory (often named Maildir) with three subdirectories named tmp, new, and cur. The subdirectories should all reside on the same filesystem. | Maildir is a format for an e-mail spool that does not require file locking to maintain message integrity because the messages are kept in separate files with unique names. A Maildir is a directory (often named Maildir) with three subdirectories named tmp, new, and cur. The subdirectories should all reside on the same filesystem. | ||
Another reason to use Maildir format is that Courier IMAP/POP3 servers only work with Maildir format of mailboxes. | Another reason to use Maildir format is that Courier IMAP/POP3 servers only work with Maildir format of mailboxes. | ||
Please find out more about Maildir [http://en.wikipedia.org/wiki/Maildir here] | |||
Please find out more about Maildir [http://en.wikipedia.org/wiki/Maildir here] | |||
Instruct Postfix to use Maildirs instead of Mboxes: | Instruct Postfix to use Maildirs instead of Mboxes: | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo postconf -e "home_mailbox = Maildir/" | sudo postconf -e "home_mailbox = Maildir/" | ||
</nowiki></pre> | </nowiki></pre> | ||
Ensure Procmail isn't used: (if the step was taken during dpkg-reconfigure, by mistake) | Ensure Procmail isn't used: (if the step was taken during dpkg-reconfigure, by mistake) | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo postconf -e "mailbox_command = " | sudo postconf -e "mailbox_command = " | ||
</nowiki></pre> | </nowiki></pre> | ||
'''Restart Postfix''' to make changes effect. | '''Restart Postfix''' to make changes effect. | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo /etc/init.d/postfix restart | sudo /etc/init.d/postfix restart | ||
</nowiki></pre> | </nowiki></pre> | ||
Test your setup again | |||
Test your setup again | |||
== Installing courier IMAP and POP3 == | == Installing courier IMAP and POP3 == | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo apt-get install courier-pop | sudo apt-get install courier-pop | ||
sudo apt-get install courier-imap | sudo apt-get install courier-imap | ||
</nowiki></pre> | </nowiki></pre> | ||
== Adding your local domains to postfix == | == Adding your local domains to postfix == | ||
Add your domains to <code><nowiki>mydestination</nowiki></code>: | Add your domains to <code><nowiki>mydestination</nowiki></code>: | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo postconf -e "mydestination = mail.fossedu.org, localhost.localdomain, localhost, yourdoamin.com" | sudo postconf -e "mydestination = mail.fossedu.org, localhost.localdomain, localhost, yourdoamin.com" | ||
</nowiki></pre> | </nowiki></pre> | ||
'''Add your local networks, too:''' | '''Add your local networks, too:''' | ||
Postfix comes with the localhost (127.0.0.1) entry; you may have others, here we assume your LAN is on 192.168.1.0/24. Make changes to suit your situation. | Postfix comes with the localhost (127.0.0.1) entry; you may have others, here we assume your LAN is on 192.168.1.0/24. Make changes to suit your situation. | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo postconf -e "mynetworks = 127.0.0.0/8, 192.168.1.0/24" | sudo postconf -e "mynetworks = 127.0.0.0/8, 192.168.1.0/24" | ||
</nowiki></pre> | </nowiki></pre> | ||
'''Make Postfix to receive mail from the Internet''' | '''Make Postfix to receive mail from the Internet''' | ||
Instruct Postfix to receive on all interfaces: | Instruct Postfix to receive on all interfaces: | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo postconf -e "inet_interfaces = all" | sudo postconf -e "inet_interfaces = all" | ||
</nowiki></pre> | </nowiki></pre> | ||
'''(optional) Make Postfix accept IPv4, IPv6 protocols''' | '''(optional) Make Postfix accept IPv4, IPv6 protocols''' | ||
If you're not using IPv6 yet, and you're paranoid, use "ipv4" instead of "all". Again, this is to suit your own network sensibilities. | If you're not using IPv6 yet, and you're paranoid, use "ipv4" instead of "all". Again, this is to suit your own network sensibilities. | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo postconf -e "inet_protocols = all" | sudo postconf -e "inet_protocols = all" | ||
</nowiki></pre> | </nowiki></pre> | ||
Finally, restart Postfix; | Finally, restart Postfix; | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo /etc/init.d/postfix restart | sudo /etc/init.d/postfix restart | ||
</nowiki></pre> | </nowiki></pre> | ||
Test your setup again using following code: | Test your setup again using following code: | ||
<pre><nowiki> | <pre><nowiki> | ||
netcat mail.yourdomain.com 25 | |||
ehlo yourdomain.com | ehlo yourdomain.com | ||
mail from: [email protected] | mail from: [email protected] | ||
第212行: | 第139行: | ||
data | data | ||
Subject: My first mail for my domain | Subject: My first mail for my domain | ||
Hi, | Hi, | ||
Are you there? | Are you there? | ||
第217行: | 第145行: | ||
Admin | Admin | ||
. (and Enter In a new Line) | . (and Enter In a new Line) | ||
quit | quit | ||
</nowiki></pre> | </nowiki></pre> | ||
Check the mailbox of <code><nowiki>fmaster</nowiki></code> | Check the mailbox of <code><nowiki>fmaster</nowiki></code> | ||
<pre><nowiki> | <pre><nowiki> | ||
su - fmaster | su - fmaster | ||
第227行: | 第153行: | ||
ls | ls | ||
</nowiki></pre> | </nowiki></pre> | ||
Now you will see mail has a separate file. | Now you will see mail has a separate file. | ||
== Testing Courier POP3 == | == Testing Courier POP3 == | ||
Type in a terminal: | Type in a terminal: | ||
<pre><nowiki> | <pre><nowiki> | ||
netcat mail.yourdomain.com 110 | |||
</nowiki></pre> | </nowiki></pre> | ||
Use the following example code segment for your test. Be intelligent to tweak the changes appropriately to your environment. An output like follows will display in your terminal. | Use the following example code segment for your test. Be intelligent to tweak the changes appropriately to your environment. An output like follows will display in your terminal. | ||
<pre><nowiki> | <pre><nowiki> | ||
Connected to mail.yourdomain.com ( | Connected to mail.yourdomain.com (208.77.188.166). | ||
Escape character is '^]'. | Escape character is '^]'. | ||
+OK Hello there. | +OK Hello there. | ||
</nowiki></pre> | </nowiki></pre> | ||
Type the following code segment in the prompt provided by the Courier POP3 server. I assume that you are intelligent enough not to type the lines which starts from <code><nowiki>+OK</nowiki></code> | |||
Type the following code segment in the prompt provided by the Courier POP3 server. I assume that you | |||
<pre><nowiki> | <pre><nowiki> | ||
user fmaster | user fmaster | ||
第255行: | 第173行: | ||
quit | quit | ||
</nowiki></pre> | </nowiki></pre> | ||
== Testing Courier IMAP == | == Testing Courier IMAP == | ||
Type in a terminal: | Type in a terminal: | ||
<pre><nowiki> | <pre><nowiki> | ||
netcat mail.yourdomain.com 143 | |||
</nowiki></pre> | </nowiki></pre> | ||
Use the following example code segment for your test. Be intelligent and tweak the changes appropriately to your environment. An output like follows will display in your terminal. | |||
Use the following example code segment for your test. Be intelligent | |||
<pre><nowiki> | <pre><nowiki> | ||
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS XCOURIEROUTBOX=INBOX.Outbox] Courier-IMAP ready. Copyright 1998-2005 Double Precision, Inc. See COPYING for distribution information. | * OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS XCOURIEROUTBOX=INBOX.Outbox] Courier-IMAP ready. Copyright 1998-2005 Double Precision, Inc. See COPYING for distribution information. | ||
</nowiki></pre> | </nowiki></pre> | ||
Type the following code segment in the prompt provided by the Courier IMAP server. | Type the following code segment in the prompt provided by the Courier IMAP server. | ||
<pre><nowiki> | <pre><nowiki> | ||
a login fmaster password | a login fmaster password | ||
第277行: | 第188行: | ||
a logout | a logout | ||
</nowiki></pre> | </nowiki></pre> | ||
== Local Alias database == | == Local Alias database == | ||
When mail is to be delivered locally, the local delivery agent runs each local recipient name through the aliases database. The mapping does not affect addresses in message headers. Local aliases are typically used to implement distribution lists, or to direct mail for standard aliases such as '''postmaster''' to real people. The table can also be used to map Firstname.Lastname addresses to login names. | When mail is to be delivered locally, the local delivery agent runs each local recipient name through the aliases database. The mapping does not affect addresses in message headers. Local aliases are typically used to implement distribution lists, or to direct mail for standard aliases such as '''postmaster''' to real people. The table can also be used to map Firstname.Lastname addresses to login names. | ||
Alias lookups are enabled by default and you will see following code segment in '''main.cf''' file. | Alias lookups are enabled by default and you will see following code segment in '''main.cf''' file. | ||
<pre><nowiki> | <pre><nowiki> | ||
... | ... | ||
alias_maps = hash:/etc/aliases | alias_maps = hash:/etc/aliases | ||
... | ... | ||
</nowiki></pre> | </nowiki></pre> | ||
=== Creating an alias for an account === | === Creating an alias for an account === | ||
The following codes illustrate how you can setup an alias. This step is optional since we are going to configure virtual mail domains later in this howto. I have added this step to make sure you understand how you can do this in case it is required. | |||
The following codes illustrate how you can setup an alias. This step is optional since we are going to configure virtual mail domains later in this howto. I have added this step to make understand how you can do this in case | |||
'''Create a user''' | '''Create a user''' | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo useradd -m -s /bin/bash sysadmin | sudo useradd -m -s /bin/bash sysadmin | ||
sudo passwd sysadmin | sudo passwd sysadmin | ||
</nowiki></pre> | </nowiki></pre> | ||
'''Edit the alias table''' | '''Edit the alias table''' | ||
Open the alias file with: | Open the alias file with: | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo vi /etc/aliases | sudo vi /etc/aliases | ||
</nowiki></pre> | </nowiki></pre> | ||
Add the following code: | Add the following code: | ||
<pre><nowiki> | <pre><nowiki> | ||
fmaster: sysadmin | fmaster: sysadmin | ||
</nowiki></pre> | </nowiki></pre> | ||
To make your changes take effect type: | |||
To make your changes effect type: | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo newaliases | sudo newaliases | ||
</nowiki></pre> | </nowiki></pre> | ||
To test your changes send a mail to <code><nowiki>fmaster</nowiki></code> and check the mail in <code><nowiki>/home/sysadmin/Maildir/new</nowiki></code> folder. | To test your changes send a mail to <code><nowiki>fmaster</nowiki></code> and check the mail in <code><nowiki>/home/sysadmin/Maildir/new</nowiki></code> folder. | ||
== Per User .forward Files == | == Per User .forward Files == | ||
Users can control their own mail delivery by specifying destinations in a file called .forward in their home directories. The syntax of these files is the same as system aliases, except that the lookup key and colon are not present. | |||
Users can control their own mail delivery by specifying destinations in a file called .forward in their home directories. The syntax of these files is the same as | |||
I will illustrate an example here: | I will illustrate an example here: | ||
Assume that you need to forward all the mails which come to the sysadmin account to an another account. Enter the following commands: | |||
Assume that you need to | |||
<pre><nowiki> | <pre><nowiki> | ||
su - sysadmin | su - sysadmin | ||
touch .forward | touch .forward | ||
</nowiki></pre> | </nowiki></pre> | ||
Then open the .forward file | Then open the .forward file | ||
<pre><nowiki> | <pre><nowiki> | ||
vi .forward | vi .forward | ||
</nowiki></pre> | </nowiki></pre> | ||
Add the following code: | Add the following code: | ||
<pre><nowiki> | <pre><nowiki> | ||
fossedu@ | fossedu@example.com | ||
</nowiki></pre> | </nowiki></pre> | ||
Remember to use email address which exists in this exercise. | Remember to use email address which exists in this exercise. | ||
Now send a mail to <code><nowiki>sysadmin</nowiki></code> and mail should come to fossedu@example.com | |||
Now send a mail to <code><nowiki>sysadmin</nowiki></code> and mail should come to fossedu@ | |||
== Postfix virtual Aliases for separate domains and Linux system accounts == | == Postfix virtual Aliases for separate domains and Linux system accounts == | ||
With this approach, every hosted domain can have its own info etc. email address. However, it still uses Linux system accounts for local mailbox deliveries. | |||
With this approach, every hosted domain can have its own info etc. email address. However, it still uses | With virtual alias domains, each hosted address is aliased to a local UNIX system account or to a remote address. The example below shows how to use this mechanism for the fossedu.org and linuxelabs.com domains. | ||
With virtual alias domains, each hosted address is aliased to a local UNIX system account or to a remote address. The example below shows how to use this mechanism for the fossedu.org and linuxelabs.com domains. | |||
Inside the '''main.cf''' file, we tell it how to handle these virtual domains: | Inside the '''main.cf''' file, we tell it how to handle these virtual domains: | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo postconf -e "virtual_alias_domains = fossedu.org linuxelabs.com" | sudo postconf -e "virtual_alias_domains = fossedu.org linuxelabs.com" | ||
sudo postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual" | sudo postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual" | ||
</nowiki></pre> | </nowiki></pre> | ||
Edit the <code><nowiki>/etc/postfix/virtual</nowiki></code> file: | Edit the <code><nowiki>/etc/postfix/virtual</nowiki></code> file: | ||
Add two Linux system accounts | Add two Linux system accounts | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo useradd -m -s /bin/bash sigiri | sudo useradd -m -s /bin/bash sigiri | ||
sudo useradd -m -s /bin/bash kala | sudo useradd -m -s /bin/bash kala | ||
</nowiki></pre> | </nowiki></pre> | ||
Set passwords for the above users. | |||
Set | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo passwd sigiri | sudo passwd sigiri | ||
sudo passwd kala | sudo passwd kala | ||
</nowiki></pre> | </nowiki></pre> | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo vi /etc/postfix/virtual | sudo vi /etc/postfix/virtual | ||
</nowiki></pre> | </nowiki></pre> | ||
Add the following code segment: | Add the following code segment: | ||
<pre><nowiki> | <pre><nowiki> | ||
[email protected] sigiri | [email protected] sigiri | ||
[email protected] kala | [email protected] kala | ||
</nowiki></pre> | </nowiki></pre> | ||
To create a Map Database type : | To create a Map Database type : | ||
<pre><nowiki> | <pre><nowiki> | ||
sudo postmap /etc/postfix/virtual | sudo postmap /etc/postfix/virtual | ||
</nowiki></pre> | </nowiki></pre> | ||
postmap is utility program that will convert <code><nowiki>/etc/postfix/virtual</nowiki></code> to <code><nowiki>/etc/postfix/virtual.db</nowiki></code> in Berkley DB format, so that Postfix can access the data faster. | |||
Restart Postfix to make changes take effect: | |||
Restart Postfix to make changes effect: | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo /etc/init.d/postfix restart | sudo /etc/init.d/postfix restart | ||
</nowiki></pre> | </nowiki></pre> | ||
Send mails to both [email protected] and [email protected] and those mails should come to mailboxes of '''sigiri''' and '''kala''' respectively. | Send mails to both [email protected] and [email protected] and those mails should come to mailboxes of '''sigiri''' and '''kala''' respectively. | ||
[[category:UbuntuHelp]] | [[category:UbuntuHelp]] |
2009年5月12日 (二) 18:26的最新版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/PostfixBasicSetupHowto }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/af | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|Afrikaans| [[::PostfixBasicSetupHowto/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/ar | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|العربية| [[::PostfixBasicSetupHowto/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/az | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|azərbaycanca| [[::PostfixBasicSetupHowto/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/bcc | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|جهلسری بلوچی| [[::PostfixBasicSetupHowto/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/bg | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|български| [[::PostfixBasicSetupHowto/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/br | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|brezhoneg| [[::PostfixBasicSetupHowto/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/ca | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|català| [[::PostfixBasicSetupHowto/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/cs | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|čeština| [[::PostfixBasicSetupHowto/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/de | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|Deutsch| [[::PostfixBasicSetupHowto/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/el | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|Ελληνικά| [[::PostfixBasicSetupHowto/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/es | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|español| [[::PostfixBasicSetupHowto/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/fa | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|فارسی| [[::PostfixBasicSetupHowto/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/fi | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|suomi| [[::PostfixBasicSetupHowto/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/fr | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|français| [[::PostfixBasicSetupHowto/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/gu | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|ગુજરાતી| [[::PostfixBasicSetupHowto/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/he | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|עברית| [[::PostfixBasicSetupHowto/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/hu | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|magyar| [[::PostfixBasicSetupHowto/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/id | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|Bahasa Indonesia| [[::PostfixBasicSetupHowto/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/it | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|italiano| [[::PostfixBasicSetupHowto/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/ja | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|日本語| [[::PostfixBasicSetupHowto/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/ko | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|한국어| [[::PostfixBasicSetupHowto/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/ksh | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|Ripoarisch| [[::PostfixBasicSetupHowto/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/mr | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|मराठी| [[::PostfixBasicSetupHowto/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/ms | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|Bahasa Melayu| [[::PostfixBasicSetupHowto/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/nl | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|Nederlands| [[::PostfixBasicSetupHowto/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/no | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|norsk| [[::PostfixBasicSetupHowto/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/oc | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|occitan| [[::PostfixBasicSetupHowto/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/pl | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|polski| [[::PostfixBasicSetupHowto/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/pt | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|português| [[::PostfixBasicSetupHowto/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/ro | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|română| [[::PostfixBasicSetupHowto/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/ru | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|русский| [[::PostfixBasicSetupHowto/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/si | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|සිංහල| [[::PostfixBasicSetupHowto/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/sq | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|shqip| [[::PostfixBasicSetupHowto/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/sr | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|српски / srpski| [[::PostfixBasicSetupHowto/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/sv | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|svenska| [[::PostfixBasicSetupHowto/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/th | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|ไทย| [[::PostfixBasicSetupHowto/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/tr | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|Türkçe| [[::PostfixBasicSetupHowto/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/vi | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|Tiếng Việt| [[::PostfixBasicSetupHowto/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/yue | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|粵語| [[::PostfixBasicSetupHowto/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/zh | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|中文| [[::PostfixBasicSetupHowto/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/zh-hans | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|中文(简体)| [[::PostfixBasicSetupHowto/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:PostfixBasicSetupHowto | UbuntuHelp:PostfixBasicSetupHowto | {{#if: | :}}PostfixBasicSetupHowto}}/zh-hant | • {{#if: UbuntuHelp:PostfixBasicSetupHowto|中文(繁體)| [[::PostfixBasicSetupHowto/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:PostfixBasicSetupHowto|:PostfixBasicSetupHowto|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :PostfixBasicSetupHowto/zh | | {{#ifexist: PostfixBasicSetupHowto/zh | | {{#ifeq: {{#titleparts:PostfixBasicSetupHowto|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:PostfixBasicSetupHowto|1|-1|}} | zh | | }}
Introduction
This document will teach you how to set up a basic Postfix mail server with IMAP and POP3 services. It does not included advanced topics such as integrating virus-checking and spam-filtering, which are dealt with in PostfixVirtualMailBoxClamSmtpHowto and PostfixCompleteVirtualMailSystemHowto.
Setup Overview
In our setup, Postfix sends and receives mail from Internet and stores them in the user mailboxes while clients on the Internet can retrieve their mails via Courier IMAP or POP3. The user authentication is done by Courier Authdaemon. The following diagram shows this process.
Anatomy of Postfix
Components
The following figure shows the main Postfix system components, and the main information flows between them.
- Yellow ellipsoids are mail programs.
- Yellow boxes are mail queues or files.
- Blue boxes are lookup tables.
- Programs in the large box run under control by the Postfix resident master daemon.
- Data in the large box is property of the Postfix mail system.
Receiving Mail
When a message enters the Postfix mail system, the first stop is the incoming queue. The figure below shows the main components that are involved with new mail.
- Mail is posted locally. The Postfix sendmail program invokes the privileged postdrop program which deposits the message into the maildrop directory, where the message is picked up by the pickup daemon. This daemon does some sanity checks, in order to protect the rest of the Postfix system.
- Mail comes in via the network. The Postfix SMTP server receives the message and does some sanity checks, in order to protect the rest of the Postfix system.
- Mail is generated internally by the Postfix system itself, in order to return undeliverable mail to the sender. The bounce or defer daemon brings the bad news.
- Mail is forwarded by the local delivery agent, either via an entry in the system-wide alias database, or via an entry in a per-user .forward file. This is indicated with the unlabeled arrow.
- Mail is generated internally by the Postfix system itself, in order to notify the postmaster of a problem (this path is also indicated with the unlabeled arrow).The Postfix system can be configured to notify the postmaster of SMTP protocol problems, UCE policy violations, and so on.
- The cleanup daemon implements the final processing stage for new mail. It adds missing From: and other message headers, arranges for address rewriting to the standard [email protected] form, and optionally extracts recipient addresses from message headers. The cleanup daemon inserts the result as a single queue file into the incoming queue, and notifies the queue manager of the arrival of new mail. The cleanup daemon can be configured to transform addresses on the basis of canonical and virtua table lookups.
- On request by the cleanup daemon, the trivial-rewrite daemon rewrites addresses to the standard [email protected] form.
Install Postfix
In this setup I assume that your domain is yourdomain.com
and it has a valid MX record setup as mail.yourdomain.com
. Remember to replace yourdomain.com
with your actual domain in the example codes in this howto. Also I assume that you know what an MX record is. To find out MX your type in a terminal:
dig mx yourdomain.com
To install postfix
sudo apt-get install postfix
Intall mailx package for use as command mail utility program. Mail command is installed with this package.
sudo apt-get install mailx
Test your default setup
Add a user before you start this.
sudo useradd -m -s /bin/bash fmaster sudo passwd fmaster
Test your default installation using the following code segment.
netcat localhost 25
Postfix will prompt like following in the terminal so that you can use to type SMTP commands.
Trying 127.0.0.1... Connected to mail.fossedu.org. Escape character is '^]'. 220 localhost.localdomain ESMTP Postfix (Ubuntu)
Type the following code segment in Postfix's prompt.
ehlo localhost mail from: root@localhost rcpt to: fmaster@localhost data Subject: My first mail on Postfix Hi, Are you there? regards, Admin . (Type the .[dot] in a new Line and press Enter ) quit
Check the mailbox of fmaster
su - fmaster mail
When you type mail
command an output like follows display in your terminal.
Mail version 8.1.2 01/15/2001. Type ? for help. "/var/mail/fmaster": 2 messages 2 new >N 1 root@localhost Mon Mar 6 12:49 13/479 Just a test N 2 root@localhost Mon Mar 6 12:51 15/487 My first mail &
You will observe that mails are indexed by numbers and you can type the number of which the mail that you want to read. For example type no "2"
to read the 2nd mail. The type "q"
to quit. The mail will be written to a file called mbox
in user's home directory. According to our example it will be /home/fmaster/mbox
.
All messages in an mbox type of mailbox are concatenated and stored in a single file. The beginning of each message is indicated by a line whose first five characters are "From " and a blank line is appended to the end of each message
Setting Postfix Support for Maildir-style Mailboxes
Maildir is a format for an e-mail spool that does not require file locking to maintain message integrity because the messages are kept in separate files with unique names. A Maildir is a directory (often named Maildir) with three subdirectories named tmp, new, and cur. The subdirectories should all reside on the same filesystem. Another reason to use Maildir format is that Courier IMAP/POP3 servers only work with Maildir format of mailboxes. Please find out more about Maildir here Instruct Postfix to use Maildirs instead of Mboxes:
sudo postconf -e "home_mailbox = Maildir/"
Ensure Procmail isn't used: (if the step was taken during dpkg-reconfigure, by mistake)
sudo postconf -e "mailbox_command = "
Restart Postfix to make changes effect.
sudo /etc/init.d/postfix restart
Test your setup again
Installing courier IMAP and POP3
sudo apt-get install courier-pop sudo apt-get install courier-imap
Adding your local domains to postfix
Add your domains to mydestination
:
sudo postconf -e "mydestination = mail.fossedu.org, localhost.localdomain, localhost, yourdoamin.com"
Add your local networks, too: Postfix comes with the localhost (127.0.0.1) entry; you may have others, here we assume your LAN is on 192.168.1.0/24. Make changes to suit your situation.
sudo postconf -e "mynetworks = 127.0.0.0/8, 192.168.1.0/24"
Make Postfix to receive mail from the Internet Instruct Postfix to receive on all interfaces:
sudo postconf -e "inet_interfaces = all"
(optional) Make Postfix accept IPv4, IPv6 protocols If you're not using IPv6 yet, and you're paranoid, use "ipv4" instead of "all". Again, this is to suit your own network sensibilities.
sudo postconf -e "inet_protocols = all"
Finally, restart Postfix;
sudo /etc/init.d/postfix restart
Test your setup again using following code:
netcat mail.yourdomain.com 25 ehlo yourdomain.com mail from: [email protected] rcpt to: [email protected] data Subject: My first mail for my domain Hi, Are you there? regards, Admin . (and Enter In a new Line) quit
Check the mailbox of fmaster
su - fmaster cd Maildir/new ls
Now you will see mail has a separate file.
Testing Courier POP3
Type in a terminal:
netcat mail.yourdomain.com 110
Use the following example code segment for your test. Be intelligent to tweak the changes appropriately to your environment. An output like follows will display in your terminal.
Connected to mail.yourdomain.com (208.77.188.166). Escape character is '^]'. +OK Hello there.
Type the following code segment in the prompt provided by the Courier POP3 server. I assume that you are intelligent enough not to type the lines which starts from +OK
user fmaster +OK Password required. pass password +OK logged in. quit
Testing Courier IMAP
Type in a terminal:
netcat mail.yourdomain.com 143
Use the following example code segment for your test. Be intelligent and tweak the changes appropriately to your environment. An output like follows will display in your terminal.
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS XCOURIEROUTBOX=INBOX.Outbox] Courier-IMAP ready. Copyright 1998-2005 Double Precision, Inc. See COPYING for distribution information.
Type the following code segment in the prompt provided by the Courier IMAP server.
a login fmaster password a OK LOGIN Ok. a logout
Local Alias database
When mail is to be delivered locally, the local delivery agent runs each local recipient name through the aliases database. The mapping does not affect addresses in message headers. Local aliases are typically used to implement distribution lists, or to direct mail for standard aliases such as postmaster to real people. The table can also be used to map Firstname.Lastname addresses to login names. Alias lookups are enabled by default and you will see following code segment in main.cf file.
... alias_maps = hash:/etc/aliases ...
Creating an alias for an account
The following codes illustrate how you can setup an alias. This step is optional since we are going to configure virtual mail domains later in this howto. I have added this step to make sure you understand how you can do this in case it is required. Create a user
sudo useradd -m -s /bin/bash sysadmin sudo passwd sysadmin
Edit the alias table Open the alias file with:
sudo vi /etc/aliases
Add the following code:
fmaster: sysadmin
To make your changes take effect type:
sudo newaliases
To test your changes send a mail to fmaster
and check the mail in /home/sysadmin/Maildir/new
folder.
Per User .forward Files
Users can control their own mail delivery by specifying destinations in a file called .forward in their home directories. The syntax of these files is the same as system aliases, except that the lookup key and colon are not present. I will illustrate an example here: Assume that you need to forward all the mails which come to the sysadmin account to an another account. Enter the following commands:
su - sysadmin touch .forward
Then open the .forward file
vi .forward
Add the following code:
[email protected]
Remember to use email address which exists in this exercise.
Now send a mail to sysadmin
and mail should come to [email protected]
Postfix virtual Aliases for separate domains and Linux system accounts
With this approach, every hosted domain can have its own info etc. email address. However, it still uses Linux system accounts for local mailbox deliveries. With virtual alias domains, each hosted address is aliased to a local UNIX system account or to a remote address. The example below shows how to use this mechanism for the fossedu.org and linuxelabs.com domains. Inside the main.cf file, we tell it how to handle these virtual domains:
sudo postconf -e "virtual_alias_domains = fossedu.org linuxelabs.com" sudo postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"
Edit the /etc/postfix/virtual
file:
Add two Linux system accounts
sudo useradd -m -s /bin/bash sigiri sudo useradd -m -s /bin/bash kala
Set passwords for the above users.
sudo passwd sigiri sudo passwd kala
sudo vi /etc/postfix/virtual
Add the following code segment:
[email protected] sigiri [email protected] kala
To create a Map Database type :
sudo postmap /etc/postfix/virtual
postmap is utility program that will convert /etc/postfix/virtual
to /etc/postfix/virtual.db
in Berkley DB format, so that Postfix can access the data faster.
Restart Postfix to make changes take effect:
sudo /etc/init.d/postfix restart
Send mails to both [email protected] and [email protected] and those mails should come to mailboxes of sigiri and kala respectively.