2009年7月27日 星期一

OUTLOOK EXPRESS 超過2G 的做法..

如果在OUTLOOK EXPRESS 仲睇到的話 , 就開一個新的FOLDER ,

把新的DBX 刪了 , 改收件匣做 新的 DBX 檔 , 就行,

如果在 OUTLOOK EXPRESS 已經看不見的話 ,

建議用一些 軟件來 修復 ( 要錢的 )

Advanced Outlook Express Repair
http://www.outlook-express-repair.com/

or

DBX TRACT
http://www.oehelp.com/Default.aspx

2009年7月13日 星期一

Solve the problem on duplicate email running on postfix + procmail

I can solve this problem using procmail with my postfixwith .procmailrc file like below

:0 Wh: msgid.lock
formail -D 32768 procmail.NO_DUPLICATES_MESSAGE_ID_CACHE


Add the above 2 line message in procmailrc file , restart the postfix.

Then , it Worked.

Postfix 安裝教學

http://linux.tnc.edu.tw/techdoc/postfix-howto.htm

2009年7月6日 星期一

Linux / Unix Command

轉貼自 http://www.computerhope.com/unix/overview.htm



Command
Description
a2p
Creates a Perl script from an awk script.
ac
Prints statistics about users' connect time.
alias
Create a name for another command or long command string.
ar
Maintain portable archive or library.
arch
Display the architecture of the current host.
arp
Manipulate the system ARP cache.
as
An assembler.
at
Command scheduler.
awk
Awk script processing program.
basename
Deletes any specified prefix from a string.
bash
Command Bourne interpreter
bc
Calculator.
bdiff
Compare large files.
bfs
Editor for large files.
bg
Continues a program running in the background.
biff
Enable / disable incoming mail notifications.
break
Break out of while, for, foreach, or until loop.
bs
Battleship game.
bye
Alias often used for the exit command.
cal
Calendar
calendar
Display appointments and reminders.
cancel
Cancels a print job.
cat
View and/or modify a file.
cc
C compiler.
cd
Change directory.
chdir
Change directory.
checkeq
Language processors to assist in describing equations.
checknr
Check nroff and troff files for any errors.
chfn
Modify your own information or if super user or root modify another users information.
chgrp
Change a groups access to a file or directory.
chkey
Change the secure RPC key pair.
chmod
Change the permission of a file.
chown
Change the ownership of a file.
chsh
Change login shell.
cksum
Display and calculate a CRC for files.
clear
Clears screen.
cls
Alias often used to clear a screen.
cmp
Compare files.
col
Reverse line-feeds filter.
comm
Compare files and select or reject lines that are common.
compress
Compress files on a computer.
continue
Break out of while, for, foreach, or until loop.
copy
Copy files.
cp
Copy files.
cpio
Creates archived CPIO files.
crontab
Create and list files that you wish to run on a regular schedule.
csh
Execute the C shell command interpreter
csplit
Split files based on context.
ctags
Create a tag file for use with ex and vi.
cu
Calls or connects to another Unix system, terminal or non-Unix system.
curl
Transfer a URL.
cut
Cut out selected fields of each line of a file.
date
Tells you the date and time in Unix.
dc
An arbitrary precision arithmetic package.
df
Display the available disk space for each mount.
deroff
Removes nroff/troff, tbl, and eqn constructs.
dhclient
Dynamic Host Configuration Protocol Client.
diff
Displays two files and prints the lines that are different.
dig
DNS lookup utility.
dircmp
Lists the different files when comparing directories.
dirname
Deliver portions of path names.
dmesg
Print or control the kernel ring buffer.
dos2unix
Converts text files between DOS and Unix formats.
dpost
Translates files created by troff into PostScript.
du
Tells you how much space a file occupies.
echo
Displays text after echo to the terminal.
ed
Line oriented file editor.
edit
Text editor.
egrep
Search a file for a pattern using full regular expressions.
elm
Program command used to send and receive e-mail.
emacs
Text editor.
enable
Enables / Disables LP printers.
env
Displays environment variables.
eqn
Language processors to assist in describing equations.
ex
Line-editor mode of the vi text editor.
exit
Exit from a program, shell or log you out of a Unix network.
expand
Expand copies of file s.
expr
Evaluate arguments as an expression.
fc
The FC utility lists or edits and re-executes, commands previously entered to an interactive sh.
fg
Continues a stopped job by running it in the foreground
fgrep
Search a file for a fixed-character string.
file
Tells you if the object you are looking at is a file or if it is a directory.
find
Finds one or more files assuming that you know their approximate filenames.
findsmb
List info about machines that respond to SMB name queries on a subnet.
finger
Lists information about the user.
fmt
Simple text formatters.
fold
Filter for folding lines.
for
Shell built-in functions to repeatedly execute action(s) for a selected number of times.
foreach
Shell built-in functions to repeatedly execute action(s) for a selected number of times.
fromdos
Converts text files between DOS and Unix formats.
fsck
Check and repair a Linux file system.
ftp
Enables ftp access to another terminal.
getfacl
Display discretionary file information.
gprof
The gprof utility produces an execution profile of a program.
grep
Finds text within a file.
groupadd
Creates a new group account.
groupdel
Enables a super user or root to remove a group.
groupmod
Enables a super user or root to modify a group.
gunzip
Expand compressed files.
gview
A programmers text editor.
gvim
A programmers text editor.
gzip
Compress files.
halt
Stop the computer.
hash
Remove internal hash table.
hashstat
Display the hash stats.
head
Displays the first ten lines of a file, unless otherwise stated.
help
If computer has online help documentation installed this command will display it.
history
Display the history of commands typed.
host
DNS lookup utility.
hostid
Prints the numeric identifier for the current host.
hostname
Set or print name of current host system.
id
Shows you the numeric user and group ID on BSD.
ifconfig
Sets up network interfaces.
ifdown
take a network interface down
ifup
bring a network interface up
isalist
Display the native instruction sets executable on this platform.
jobs
List the jobs currently running in the background.
join
Joins command forms together.
keylogin
Decrypt the user's secret key.
kill
Cancels a job.
ksh
Korn shell command interpreter.
ld
Link-editor for object files.
ldd
List dynamic dependencies of executable files or shared objects.
less
Opposite of the more command.
lex
Generate programs for lexical tasks.
link
Calls the link function to create a link to a file.
ln
Creates a link to a file.
lo
Allows you to exit from a program, shell or log you out of a Unix network.
locate
List files in databases that match a pattern.
login
Signs into a new system.
logname
Returns users login name.
logout
Logs out of a system.
lp
Prints a file on System V systems.
lpadmin
Configure the LP print service.
lpc
Line printer control program.
lpq
Lists the status of all the available printers.
lpr
Submits print requests.
lprm
Removes print requests from the print queue.
lpstat
Lists status of the LP print services.
ls
Lists the contents of a directory.
mach
Display the processor type of the current host.
mail
One of the ways that allows you to read/send E-Mail.
mailcompat
Provide SunOS 4.x compatibility for the Solaris mailbox format.
mailx
Mail interactive message processing system.
make
Executes a list of shell commands associated with each target.
man
Display a manual of a command.
mesg
Control if non-root users can send text messages to you.
mii-tool
View, manipulate media-independent interface status.
mkdir
Create a directory.
mkfs
Build a Linux file system, usually a hard disk partition.
more
Displays text one screen at a time.
mount
Disconnects a file systems and remote resources.
mt
Magnetic tape control.
mv
Renames a file or moves it from one directory to another directory.
nc
TCP/IP swiss army knife.
neqn
Language processors to assist in describing equations.
netstat
Shows network status.
newalias
Install new elm aliases for user and/or system.
newform
Change the format of a text file.
newgrp
Log into a new group.
nice
Invokes a command with an altered scheduling priority.
niscat
Display NIS+ tables and objects.
nischmod
Change access rights on a NIS+ object.
nischown
Change the owner of a NIS+ object.
nischttl
Change the time to live value of a NIS+ object.
nisdefaults
Display NIS+ default values.
nisgrep
Utilities for searching NIS+ tables.
nismatch
Utilities for searching NIS+ tables.
nispasswd
Change NIS+ password information.
nistbladm
NIS+ table administration command.
nmap
Network exploration tool and security / port scanner.
nohup
Runs a command even if the session is disconnected or the user logs out.
nroff
Formats documents for display or line-printer.
nslookup
Queries a name server for a host or domain lookup.
on
Execute a command on a remote system, but with the local environment.
onintr
Shell built-in functions to respond to (hardware) signals.
optisa
Determine which variant instruction set is optimal to use.
pack
Shrinks file into a compressed file.
pagesize
Display the size of a page of memory in bytes, as returned by getpagesize.
passwd
Allows you to change your password.
paste
Merge corresponding or subsequent lines of files.
pax
Read / write and writes lists of the members of archive files and copy directory hierarchies.
pcat
Compresses file.
perl
Perl is a programming language optimized for scanning arbitrary text files, extracting information from those text files.
pg
Files perusal filters for CRTs.
pgrep
Examine the active processes on the system and reports the process IDs of the processes
pico
Simple and very easy to use text editor in the style of the Pine Composer.
pine
Command line program for Internet News and Email.
ping
Sends ICMP ECHO_REQUEST packets to network hosts.
pkill
Examine the active processes on the system and reports the process IDs of the processes
poweroff
Stop the computer.
pr
Formats a file to make it look better when printed.
priocntl
Display's or set scheduling parameters of specified process(es)
printf
Write formatted output.
ps
Reports the process status.
pvs
Display the internal version information of dynamic objects within an ELF file.
pwd
Print the current working directory.
quit
Allows you to exit from a program, shell or log you out of a Unix network.
rcp
Copies files from one computer to another computer.
reboot
Stop the computer.
red
Line oriented file editor.
rehash
Recomputes the internal hash table of the contents of directories listed in the path.
remsh
Runs a command on another computer.
repeat
Shell built-in functions to repeatedly execute action(s) for a selected number of times.
rgview
A programmers text editor.
rgvim
A programmers text editor.
rlogin
Establish a remote connection from your terminal to a remote machine.
rm
Deletes a file without confirmation (by default).
rmail
One of the ways that allows you to read/send E-Mail.
rmdir
Deletes a directory.
rn
Reads newsgroups.
route
Show / manipulate the IP routing table.
rpcinfo
Report RPC information.
rsh
Runs a command on another computer.
rsync
Faster, flexible replacement for rcp.
rview
A programmers text editor.
rvim
A programmers text editor.
s2p
Convert a sed script into a Perl script.
sag
Graphically displays the system activity data stored in a binary data file by a previous sar run.
sar
Displays the activity for the CPU.
script
Records everything printed on your screen.
sdiff
Compares two files, side-by-side.
sed
Allows you to use pre-recorded commands to make changes to text.
sendmail
Sends mail over the Internet.
set
Set the value of an environment variable.
setenv
Set the value of an environment variable.
setfacl
Modify the Access Control List (ACL) for a file or files.
settime
Change file access and modification time.
sftp
Secure file transfer program.
sh
Runs or processes jobs through the Bourne shell.
shred
Delete a file securely, first overwriting it to hide its contents.
shutdown
Turn off the computer immediately or at a specified time.
sleep
Waits a x amount of seconds.
slogin
OpenSSH SSH client (remote login program).
smbclient
An ftp-like client to access SMB/CIFS resources on servers.
sort
Sorts the lines in a text file.
spell
Looks through a text file and reports any words that it finds in the text file that are not in the dictionary.
split
Split a file into pieces.
stat
Display file or filesystem status.
stop
Control process execution.
strip
Discard symbols from object files.
stty
Sets options for your terminal.
su
Become super user or another user.
sysinfo
Get and set system information strings.
sysklogd
Linux system logging utilities.
tabs
Set tabs on a terminal.
tail
Delivers the last part of the file.
talk
Talk with other logged in users.
tac
Concatenate and print files in reverse.
tar
Create tape archives and add or extract files.
tbl
Preprocessor for formatting tables for nroff or troff.
tcopy
Copy a magnetic tape.
tcpdump
Dump traffic on a network.
tee
Read from an input and write to a standard output or file.
telnet
Uses the telnet protocol to connect to another remote computer.
time
Used to time a simple command.
timex
The timex command times a command; reports process data and system activity.
todos
Converts text files between DOS and Unix formats.
top
Display Linux tasks.
touch
Change file access and modification time.
tput
Initialize a terminal or query terminfo database.
tr
Translate characters.
traceroute
Print the route packets take to network host.
troff
Typeset or format documents.
ul
Reads the named filenames or terminal and does underlining.
umask
Get or set the file mode creation mask.
unalias
Remove an alias.
unhash
Remove internal hash table.
uname
Print name of current system.
uncompress
Uncompressed compressed files.
uniq
Report or filter out repeated lines in a file.
unmount
Crates a file systems and remote resources.
unpack
Expands a compressed file.
untar
Create tape archives and add or extract files.
until
Execute a set of actions while/until conditions are evaluated TRUE.
useradd
Create a new user or updates default new user information.
userdel
Remove a users account.
usermod
Modify a users account.
vacation
Reply to mail automatically.
vedit
Screen-oriented (visual) display editor based on ex.
vgrind
Grind nice program listings
vi
Screen-oriented (visual) display editor based on ex.
vim
A programmers text editor.
view
A programmers text editor.
w
Show who is logged on and what they are doing.
wait
Await process completion.
wc
Displays a count of lines, words, and characters in a file
whereis
Locate a binary, source, and manual page files for a command.
while
Repetitively execute a set of actions while/until conditions are evaluated TRUE.
which
Locate a command.
who
Displays who is on the system.
whois
Internet user name directory service.
write
Send a message to another user.
X
Execute the X windows system.
xfd
Display all the characters in an X font.
xlsfonts
Server font list displayer for X.
xset
User preference utility for X.
xterm
Terminal emulator for X.
xrdb
X server resource database utility.
yacc
Short for yet another compiler-compiler, yacc is a compiler.
yes
Repeatedly output a line with all specified STRING(s), or 'y'.
yppasswd
Changes network password in the NIS database.
zcat
Compress files.

2009年7月1日 星期三

Postfix 淺述

一、 postfix概述
postfix是Wietse Venema在IBM的GPL協議之下開發的MTA(郵件傳輸代理)軟件。下面一段話摘自postfix的官方站點(http://www.postfix.org):“postfix是Wietse Venema想要為使用最廣泛的sendmail提供替代品的一個嘗試。在Internet世界中,大部分的電子郵件都是通過sendmail來投遞的,大約有100萬用戶使用sendmail,每天投遞上億封郵件。這真實一個讓人吃驚的數字。Postfix試圖更快、更容易管理、更安全,同時還與 sendmail保持足夠的兼容性。”
1.1 postfix的特點1. postfix是免費的:postfix想要作用的范圍是廣大的Internet用戶,試圖影響大多數的Internet上的電子郵件系統,因此它是免費的。2. 更快:postfix在性能上大約比sendmail快三倍。一部運行postfix的台式PC每天可以收發上百萬封郵件。3. 兼容性好:postfix是sendmail兼容的,從而使sendmail用戶可以很方便地遷移到postfix。Postfix支持/var[/spool]/mail、/etc/aliases、 NIS、和 ~/.forward 文件。4. 更健壯:postfix被設計成在重負荷之下仍然可以正常工作。當系統運行超出了可用的內存或磁盤空間時,postfix會自動減少運行進程的數目。當處理的郵件數目增長時,postfix運行的進程不會跟著增加。5. 更靈活:postfix是由超過一打的小程序組成的,每個程序完成特定的功能。你可以通過配置文件設置每個程序的運行參數。6. 安全性postfix具有多層防御結構,可以有效地抵御惡意入侵者。如大多數的postfix程序可以運行在較低的權限之下,不可以通過網絡訪問安全性相關的本地投遞程序等等。
1.2 postfix的總體結構postfix由十幾個具有不同功能的半駐留進程組成,並且在這些進程中並無特定的進程間父子關系。某一個特定的進程可以為其他進程提供特定的服務。大多數的postfix進程由一個進程統一進行管理,該進程負責在需要的時候調用其他進程,這個管理進程就是master進程。該進程也是一個後台程序。這些postfix進程是可以配置的,我們可以配置每個進程運行的數目,可重用的次數,生存的時間等等。通過靈活的配置特性可以使整個系統的運行成本大大降低。
1.2.1 postfix的郵件隊列(mail queues)postfix有四種不同的郵件隊列,並且由隊列管理進程統一進行管理:1. maildrop:本地郵件放置在maildrop中,同時也被拷貝到incoming中。2. incoming:放置正在到達或隊列管理進程尚未發現的郵件。3. active:放置隊列管理進程已經打開了並正準備投遞的郵件,該隊列有長度的限制。4. deferred:放置不能被投遞的郵件。隊列管理進程僅僅在內存中保留active隊列,並且對該隊列的長度進行限制,這樣做的目的是為了避免進程運行內存超過系統的可用內存。
1.2.2 postfix對郵件風暴的處理當有新的郵件到達時,postfix進行初始化,初始化時postfix同時只接受兩個並發的連接請求。當郵件投遞成功後,可以同時接受的並發連接的數目就會緩慢地增長至一個可以配置的值。當然,如果這時系統的消耗已到達系統不能承受的負載就會停止增長。還有一種情況時,如果postfix在處理郵件過程中遇到了問題,則該值會開始降低。當接收到的新郵件的數量超過postfix的投遞能力時,postfix會暫時停止投遞deferred隊列中的郵件而去處理新接收到的郵件。這是因為處理新郵件的延遲要小於處理deferred隊列中的郵件。Postfix會在空閑時處理deferred中的郵件。
1.2.3 postfix對無法投遞的郵件的處理當一封郵件第一次不能成功投遞時,postfix會給該郵件貼上一個將來的時間郵票。郵件隊列管理程序會忽略貼有將來時間郵票的郵件。時間郵票到期時, postfix會嘗試再對該郵件進行一次投遞,如果這次投遞再次失敗,postfix就給該郵件貼上一個兩倍於上次時間郵票的時間郵票,等時間郵票到期時再次進行投遞,依此類推。當然,經過一定次數的嘗試之後,postfix會放棄對該郵件的投遞,返回一個錯誤信息給該郵件的發件人。
1.2.4 postfix對不可到達的目的地郵件的處理postfix會在內存中保存一個有長度限制的當前不可到達的地址列表。這樣就避免了對那些目的地為當前不可到達地址的郵件的投遞嘗試。從而大大提高了系統的性能。
1.2.2 postfix的安全性postfix通過一系列的措施來提高系統的安全性,這些措施包括:1. 動態分配內存,從而防止系統緩沖區溢出;2. 把大郵件分割成幾塊進行處理,投遞時再重組;3. Postfix的各種進程不在其他用戶進程的控制之下運行,而是運行在駐留主進程master的控制之下,與其他用戶進程無父子關系,所有有很好的絕緣性。4. Postfix的隊列文件有其特殊的格式,只能被postfix本身識別;
二、 postfix對郵件的處理過程
2.1 接收郵件的過程
圖二、postfix對接收郵件的處理
當postfix接收到一封新郵件時,新郵件首選在incoming隊列處停留,然後針對不同的情況進行不同的處理:1.對於來自於本地的郵件:sendmail進程負責接收來自本地的郵件放在maildrop隊列中,然後pickup進程對maildrop中的郵件進行完整性檢測。maildrop目錄的權限必須設置為某一用戶不能刪除其他用戶的郵件。2.對於來自於網絡的郵件:smtpd進程負責接收來自於網絡的郵件,並且進行安全性檢測。可以通過UCE(unsolicited commercial email)控制smtpd的行為。3.由postfix進程產生的郵件:這是為了將不可投遞的信息返回給發件人。這些郵件是由bounce後台程序產生的。5. 由postfix自己產生的郵件:提示postmaster(也即postfix管理員)postfix運行過程中出現的問題。(如SMTP協議問題,違反UCE規則的記錄等等。)
關於cleanup後台程序的說明:cleanup是對新郵件進行處理的最後一道工序它對新郵件進行以下的處理:添加信頭中丟失的Form信息;為將地址重寫成標準的user@fully.qualified.domain格式進行排列;重信頭中抽出收件人的地址;將郵件投入incoming隊列中,並請求郵件隊列管理進程處理該郵件;請求trivial-rewrite進程將地址轉換成標準的user@fully.qualified.domain格式。
2.2 投遞郵件的過程新郵件一旦到達incoming隊列,下一步就是開始投遞郵件,postfix投遞郵件時的處理過程如圖三所示。相關的說明如下:郵件隊列管理進程是整個postfix郵件系統的心臟。它和local、smtp、pipe等投遞代理相聯系,將包含有隊列文件路徑信息、郵件發件人地址、郵件收件人地址的投遞請求發送給投遞代理。隊列管理進程維護著一個deferred隊列,那些無法投遞的郵件被投遞到該隊列中。除此之外,隊列管理進程還維護著一個active隊列,該隊列中的郵件數目是有限制的,這是為了防止在負載太大時內存溢出。郵件隊列管理程序還負責將收件人地址在 relocated表中列出的郵件返回給發件人,該表包含無效的收件人地址。
如果郵件隊列管理進程請求,rewrite後台程序對收件人地址進行解析。但是缺省地,rewrite只對郵件收件人是本地的還是遠程的進行區別。如果郵件對你管理進程請求,bounce後台程序可以生成一個郵件不可投遞的報告。本地投遞代理local進程可以理解類似UNIX風格的郵箱,sendmail風格的系統別名數據庫和sendmail風格的.forward文件。可以同時運行多個local進程,但是對同一個用戶的並發投遞進程數目是有限制的。你可以配置local將郵件投遞到用戶的宿主目錄,也可以配置local將郵件發送給一個外部命令,如流行的本地投遞代理procmail。在流行的linux發行版本RedHat中,我們就使用procmail作為最終的本地投遞代理。遠程投遞代理SMTP進程根據收件人地址查詢一個SMTP服務器列表,按照順序連接每一個SMTP服務器,根據性能對該表進行排序。在系統負載太大時,可以有數個並發的SMTP進程同時運行。pipe是用於UUCP協議的投遞代理。
三、 postfix的安裝過程
3.1源代碼包的安裝1. 獲取postfix的源代碼包從postfix官方站點www.postfix.org取得postfix的源代碼包postfix-19991231-pl08.tar.gz。將其拷貝到/tmp2.解開源代碼包,將生成/tmp/ postfix-19991231-pl08目錄。tar xvzf postfix-19991231-pl08.tar.gz3.編譯源代碼包cd /tmp/ postfix-19991231-pl08make4.建立一個新用戶“postfix”,該用戶必須具有唯一的用戶id和組id號,同時應該讓該用戶不能登錄到系統,也即不為該用戶指定可執行的登錄外殼程序和可用的用戶宿主目錄。我們可以先用adduser postfix 添加用戶再編輯/etc/passwd文件中的相關條目如下所示:postfix:*:12345:12345ostfix:/no/where:/no/shell5.確定/etc/aliases文件中包含如下的條目:postfix: root6. 以root用戶登錄,在/tmp/ postfix-19991231-pl08目錄下執行命令:./INSTALL.sh7. 啟動postfix# postfix start8.關於maildrop目錄權限的說明:postfix可以使用一個所有用戶都可寫的(也即目錄權限為1773)的maildrop目錄來讓本地用戶提交郵件。這種方法避免了使用set-uid 或 set-gid 軟件,並且在郵件系統不可用時,用戶仍然可以提交郵件。其他用戶沒有訪問該目錄中的隊列文件的權限。接收來自網絡的郵件時postfix不使用 maildrop目錄。但是,由於該目錄的權限是733,其他用戶可以建立一個硬連接到該目錄中的文件從而導致該郵件被投遞多次或無法刪除,也就是說這將導致安全性問題。如果你想要使用這種方式來讓用戶提交郵件,就要在INSTALL.sh 腳本問你是否需要set-gid 時回答no。如果你的系統有多個用戶的話,最好取消以上的方式而採用利用set-gid 用戶權限提交郵件的方式。這時,我們首先需要建立一個組id唯一的組"maildrop" 並且確定該組中沒有用戶成員。然後在INSTALL.sh 問你是否需要set-gid 時指定"maildrop"。提示:在安裝postfix之前,請刪除已經安裝的sendmail。
3.2 rpm包的安裝1. 獲取postfix的rpm軟件包。我們可以從http://www.alltrading.es/postfix/RPMS/i386/ 獲得postfix的rpm軟件包。當前的最新版本是postfix-20000531-2.i386.rpm。2. 備份你的/etc/aliases和/etc/aliases.db,因為postfix要使用該別名數據庫。3. 用以下命令查看系統是否安裝了sendmail:[root@mail /root]# rpm -qa grep sendmailsendmail-doc-8.9.3-15sendmail-8.9.3-15sendmail-cf-8.9.3-154. 用以下命令強行卸載sendmail:[root@mail /root]# rpm -e sendmail sendmail-cf sendmail-doc --nodeps5. 用以下命令殺死運行中的sendmail進程:[root@mail /root]# killall sendmail6. 安裝postfix:[root@mail /root]# rpm -Uvh postfix-20000531-2.i386.rpmpostfix ##################################################postfix-script: warning: creating missing Postfix pid directorypostfix-script: warning: creating missing Postfix incoming directorypostfix-script: warning: creating missing Postfix active directorypostfix-script: warning: creating missing Postfix bounce directorypostfix-script: warning: creating missing Postfix defer directorypostfix-script: warning: creating missing Postfix deferred directorypostfix-script: warning: creating missing Postfix saved directorypostfix-script: warning: creating missing Postfix corrupt directorypostfix-script: warning: creating missing Postfix public directorypostfix-script: warning: creating missing Postfix private directory[root@mail /root]#7. 啟動postfix[root@mail /root]# /etc/rc.d/init.d/postfix start
3.3 配置系統每次啟動時自動啟動postfix1.如果你安裝的是postfix的源代碼包,可以在/etc/rc.d/rc.local文件中加入如下的語句讓系統每次啟動時自動啟動postfix:if [ -f /usr/libexec/postfix ]; then/usr/libexec/postfix startfi2.如果你安裝的是postfix的rpm包,可以通過setup命令來設置在系統啟動時啟動postfix。
四、 postfix的配置詳解
4.1 postfix的配置文件結構postfix的配置文件位於/etc/postfix下,安裝完postfix以後,我們可以通過ls命令查看postfix的配置文件:[root@mail postfix]# lsinstall.cf main.cf master.cf postfix-script
這四個文件就是postfix最基本的配置文件,它們的區別在於:mail.cf:是postfix主要的配置文件。Install.cf:包含安裝過程中安裝程序產生的postfix初始化設置。master.cf:是postfix的master進程的配置文件,該文件中的每一行都是用來配置postfix的組件進程的運行方式。postfix-script:包裝了一些postfix命令,以便我們在linux環境中安全地執行這些postfix命令。
4.2 postfix的基本配置postfix大約有100個配置參數,這些參數都可以通過main.cf 指定。配置的格式是這樣的,用等號連接參數和參數的值。如:myhostname = mail.mydomain.com等號的左邊是參數的名稱,等號的右邊是參數的值; 當然,我們也可以在參數的前面加上$來引用該參數,如:myorigin = $myhostname雖然postfix有100個左右的參數,但是postfix為大多數的參數都設置了缺省值,所以在讓postfix正常為你服務之前,你只需要配置為數不多的幾個參數。下面我們一起來看一看這些基本的postfix參數。需要注意的是,一旦你更改了main.cf文件的內容,則必須運行postfix reload命令使其生效。
1. myoriginmyorigin參數指明發件人所在的域名。如果你的用戶的郵件地址為user@domain.com,則該參數指定@後面的域名。缺省地, postfix使用本地主機名作為myorigin,但是建議你最好使用你的域名,因為這樣更具有可讀性。比如:安裝postfix的主機為 mail.domain.com則我們可以這樣指定myorigin:myorigin = domain.com當然我們也可以引用其他參數,如:myorigin = $mydomain
2. mydestinationmydestination參數指定postfix接收郵件時收件人的域名,換句話說,也就是你的postfix系統要接收什麼樣的郵件。比如:你的用戶的郵件地址為user@domain.com, 也就是你的域為domain.com, 則你就需要接收所有收件人為user_name@domain.com的郵件。與myorigin一樣,缺省地,postfix使用本地主機名作為 mydestination。如:mydestination = $mydomainmydestination = domain.com
3. notify_classes在postfix系統中,必須指定一個postfix系統管理員的別名指向一個用戶,只有這樣,在用戶遇到問題時才有報告的對象,postfix也才能將系統的問題報告給管理員。notify_classes參數就是用來指定向postfix管理員報告錯誤時的信息級別。共有以下幾種級別:
bounce:將不可以投遞的郵件的拷貝發送給postfix管理員。出於個人隱私的緣故,該郵件的拷貝不包含信頭。
2bounce:將兩次不可投遞的郵件拷貝發送給postfix管理員。
delay:將郵件的投遞延遲信息發送給管理員,僅僅包含信頭。
policy:將由於UCE規則限制而被拒絕的用戶請求發送給postfix管理員,包含整個SMTP會話的內容。
protocol:將協議的錯誤信息或用戶企圖執行不支持的命令的記錄發送給postfix管理員。同樣包含整個SMTP會話的內容。
resource:將由於資源錯誤而不可投遞的錯誤信息發送給postfix管理員,比如:隊列文件寫錯誤等等。
software:將由於軟件錯誤而導致不可投遞的錯誤信息發送給postfix管理員。
缺省值為:notify_classes = resource, software
4.myhostnamemyhostname 參數指定運行postfix郵件系統的主機的主機名。缺省地,該值被設定為本地機器名。你也可以指定該值,需要注意的是,要指定完整的主機名。如:myhostname = mail.domain.com
5.mydomainmydomain參數指定你的域名,缺省地,postfix將myhostname的第一部分刪除而作為mydomain的值。你也可以自己指定該值,如:mydomain = domain.com
6.mynetworksmynetworks 參數指定你所在的網絡的網絡地址,postfix系統根據其值來區別用戶是遠程的還是本地的,如果是本地網絡用戶則允許其訪問。你可以用標準的A、B、C類網絡地址,也可以用CIDR(無類域間路由)地址來表示,如:192.168.1.0/24192.168.1.0/26
7.inet_interfacesinet_interfaces 參數指定postfix系統監聽的網絡接口。缺省地,postfix監聽所有的網絡接口。如果你的postfix運行在一個虛擬的ip地址上,則必須指定其監聽的地址。如:inet_interfaces = allinet_interface = 192.168.1.1
4.3 postfix的UCE(unsolicited commercial email)控制所謂UCE控制就是指控制postfix接收或轉發來自於什麼地方的郵件。
缺省地,postfix轉發符合以下條件的郵件:* 來自客戶端ip地址符合$mynetworks的郵件。* 來自客戶端主機名符合$relay_domains及其子域的郵件。* 目的地為$relay_domains及其子域的郵件。
缺省地,postfix接受符合以下條件的郵件:* 目的地為$inet_interfaces的郵件。* 目的地為$mydestination的郵件。* 目的地為$virtual_maps的郵件。但是我們也可以通過下面的規則來實現更強大的控制功能。
1. 信頭過濾通過header_checks參數限制接收郵件的信頭的格式,如果符合指定的格式,則拒絕接收該郵件。可以指定一個或多個查詢列表,如果新郵件的信頭符合列表中的某一項則拒絕該接收郵件。如:header_checks = regexp:/etc/postfix/header_checksheader_checks = pcre:/etc/postfix/header_checks缺省地,postfix不進行信頭過濾。
2.客戶端主機名/地址限制通過smtpd_client_restrictions參數限制可以向postfix發起SMTP 連接的客戶端的主機名或ip地址。可以指定一個或多個參數值,中間用逗號隔開。限制規則是按照查詢的順序進行的,第一條符合條件的規則被執行。可用的規則有:
reject_unknown_client:如果客戶端的ip地址在DNS中沒有PTR記錄則拒絕轉發該客戶端的連接請求。可以用 unknown_client_reject_code參數指定返回給客戶機的錯誤代碼(缺省為450)。如果你有用戶沒有作 DNS記錄則不要啟用該選項。
permit_mynetworks:如果客戶端的ip地址符合$mynetworks參數定義的范圍則接受該客戶端的連接請求,並轉發該郵件。
check_client_access maptype:mapname:根據客戶端的主機名、父域名、ip地址或屬於的網絡搜索access數據庫。如果搜索的結果為REJECT 或者 "[45]XX text" 則拒絕該客戶端的連接請求;如果搜索的結果為OK、RELAY 或數字則接受該客戶端的連接請求,並轉發該郵件。。可以用access_map_reject_code參數指定返回給客戶機的錯誤代碼(缺省為 554)。
reject_maps_rbl:如果客戶端的網絡地址符合$maps_rbl_domains參數的值則拒絕該客戶端的連接請求。可以用maps_rbl_reject_code參數指定返回給客戶機的錯誤代碼(缺省為554)。
示例:smtpd_client_restrictions = hash:/etc/postfix/access, reject_maps_rblsmtpd_client_restrictions = permit_mynetworks, reject_unknown_client該參數的缺省值為:smtpd_client_restrictions =也即接收來自任何客戶端的SMTP連接。
3. 是否請求HELO命令可以通過smtpd_helo_required參數指定客戶端在SMTP會話的開始是否發送一個HELO命令。你可以指定該參數的值為yes或no。缺省值為:smtpd_helo_required = no
4. HELO主機名限制可以通過smtpd_helo_restrictions參數指定客戶端在執行HELO命令時發送給postfix的主機名。缺省地,postfix接收客戶端發送的任意形式的主機名。可以指定一個或多個參數值,中間用逗號隔開。限制規則是按照查詢的順序進行的,第一條符合條件的規則被執行。可用的規則有:reject_invalid_hostname:如果HELO命令所帶的主機名參數不符合語法規范則拒絕客戶機的連接請求。可以用invalid_hostname_reject_code參數指定返回給客戶機的錯誤代碼(缺省為501)。
permit_naked_ip_address:RFC要求客戶端的HELO命令包含的ip地址放在方括號內,你可以用permit_naked_ip_address參數取消該限制。因為有的mail客戶端不遵守該RFC的規定。
reject_unknown_hostname:如果客戶端執行HELO命令時的主機名在DNS中沒有相應的A 或 MX 記錄則拒絕該客戶端的連接請求。可以用invalid_hostname_reject_code參數指定返回給客戶機的錯誤代碼(缺省為450)。
reject_non_fqdn_hostname:如果客戶端執行HELO命令時的主機名不是RFC規定的完整的域名則拒絕客戶端的連接請求。可以用invalid_hostname_reject_code參數指定返回給客戶機的錯誤代碼(缺省為504)。
check_helo_access maptype:mapname:根據客戶端HELO的主機名、父域名搜索access數據庫。如果搜索的結果為REJECT 或者 "[45]XX text" 則拒絕該客戶端的連接請求;如果搜索的結果為OK、RELAY 或數字則接受該客戶端的連接請求。可以用access_map_reject_code參數指定返回給客戶機的錯誤代碼(缺省為554)。
示例:smtpd_helo_restrictions = permit_mynetworks, reject_invalid_hostname
5. RFC 821信頭限制RFC 821對郵件的信頭做了嚴格的規定,但是廣泛使用的sendmail並不支持該規定,所以對於該參數我們只能說不,即:strict_rfc821_envelopes = no
6. 通過發件人地址進行限制可以用smtpd_sender_restrictions參數通過發件人在執行MAIL FROM命令時提供的地址進行限制。可以指定一個或多個參數值,中間用逗號隔開。限制規則是按照查詢的順序進行的,第一條符合條件的規則被執行。可用的規則有:
reject_unknown_sender_domain:如果MAIL FROM命令提供的主機名在DNS中沒有相應的A 或 MX 記錄則拒絕該客戶端的連接請求。可以用unknown_address_reject_code參數指定返回給客戶機的錯誤代碼(缺省為450)。
check_sender_access maptype:mapname:根據MAIL FROM命令提供的主機名、父域搜索access數據庫。如果搜索的結果為REJECT 或者 "[45]XX text" 則拒絕該客戶端的連接請求;如果搜索的結果為OK、RELAY 或數字則接受該客戶端的連接請求。可以用access_map_reject_code參數指定返回給客戶機的錯誤代碼(缺省為554)。可以通過該參數過濾來自某些不受歡迎的發件人的郵件。
reject_non_fqdn_sender:如果MAIL FROM命令提供的主機名不是RFC規定的完整的域名則拒絕客戶端的連接請求。可以用non_fqdn_reject_code 參數指定返回給客戶機的錯誤代碼(缺省為504)。缺省地,postfix接受來自任何發件人的郵件。示例:smtpd_sender_restrictions = hash:/etc/postfix/access, reject_unknown_sender_domain
7. 通過收件人地址進行過濾可以用smtpd_recipient_restrictions參數通過發件人在執行RCPT TO命令時提供的地址進行限制。缺省值為:smtpd_recipient_restrictions = permit_mynetworks, check_relay_domains可以指定一個或多個參數值,中間用逗號隔開。限制規則是按照查詢的順序進行的,第一條符合條件的規則被執行。可用的規則有:
check_relay_domains:如果符合以下的條件,則接受SMTP連接請求,否則拒絕該連接,可以用relay_domains_reject_code 參數指定返回給客戶機的錯誤代碼(缺省為504)。* 客戶端主機名符合$relay_domains及其子域* 目的地為$inet_interfaces、$mydestination或$virtual_maps
permit_auth_destination:不管客戶端的主機名,只要符合以下的條件,就接受SMTP連接請求:* 解析後的目標地址符合$relay_domains及其子域* 解析後的目標地址符合$inet_interfaces、$mydestination或$virtual_maps
reject_unauth_destination:不管客戶端的主機名,只要符合以下的條件,就拒絕該客戶端SMTP連接請求:* 解析後的目標地址符合$relay_domains及其子域* 解析後的目標地址符合$inet_interfaces、$mydestination或$virtual_maps
check_recipient_access:根據解析後的目標地址、父域搜索access數據庫。如果搜索的結果為REJECT 或者 "[45]XX text" 則拒絕該客戶端的連接請求;如果搜索的結果為OK、RELAY 或數字則接受該客戶端的連接請求。可以用access_map_reject_code參數指定返回給客戶機的錯誤代碼(缺省為554)。
reject_unknown_recipient_domain:如果收件人的郵件地址在DNS中沒有相應的A 或 MX 記錄則拒絕該客戶端的連接請求。可以用unknown_address_reject_code參數指定返回給客戶機的錯誤代碼(缺省為450)。
reject_non_fqdn_recipient:如果發件人在執行RCPT TO命令時提供的地址不是完整的域名則拒絕其SMTP連接請求。可以用The non_fqdn_reject_code參數指定返回給客戶機的錯誤代碼(缺省為504)。
4.4 posftfix的性能控制之所以對postfix的性能進行控制,是為了在遇到郵件風暴時保証postfix可以正常運行。通常,我們可以通過對下列postfix參數的配置來調節postfix的性能,這些參數都是通過mail.cf配置文件進行配置的,修改以後不要忘了運行postfix reload命令來使配置生效。
1. 進程數限制可以通過default_process_limit 參數來控制postfix系統同時可以運行的最大進程數目。缺省值是50個。
2. 對同一目標主機的並發連接限制當向同一目標主機發出SMTP連接時,postfix初始化發出兩個SMTP連接,如果投遞成功則增加並發的SMTP連接數目,遇到擁塞時又減少並發連接的數目。postfix中通過以下的參數對同一目標主機的並發連接進行控制:* initial_destination_concurrency:控制對同一目標主機的初始化並發連接數目。缺省值為2。* default_destination_concurrency_limit:控制初始化連接後對同一目標主機的最大並發連接數目。缺省值為10。* local_destination_concurrency_limit:控制對同一本地收件人的最大同時投遞的郵件數目。缺省值為2,因為對本地同一收件人投遞郵件時投遞工作只能一個接一個的進行,所以設得在大也沒用。
3. 對同一封郵件的收件人數目限制通過default_destination_recipient_limit參數來控制postfix的投遞代理(如smtp進程)可以將同一封郵件發送給多少個收件人。缺省值為50。也可以用明確指出該投遞代理的參數來覆蓋該缺省值。如用 smtpd_recipient_limit來指定smtp投遞代理可以將同一封郵件發送給多少個收件人,該參數的缺省值為1000。
4. 推遲投遞控制通過defer_transports參數,我們可以推遲投遞該參數指定的郵件直到postfix明確的提出投遞要求。下面我們看一個例子:有一個小型的局域網,用戶都將郵件發送給局域網內燦始?系苀postfix安裝與配置一、 postfix概述postfix是Wietse Venema在IBM的GPL協議之下開發的MTA(郵件傳輸代理)軟件。下面一段話摘自postfix的官方站點(http://www.postfix.org):“postfix是Wietse Venema想要為使用最廣泛的sendmail提供替代品的一個嘗試。在Internet世界中,大部分的電子郵件都是通過sendmail來投遞的,大約有100萬用戶使用sendmail,每天投遞上億封郵件。這真實一個讓人吃驚的數字。Postfix試圖更快、更容易管理、更安全,同時還與 sendmail保持足夠的兼容性。
5. 關於延遲郵件的再投遞控制可以通過以下的幾個參數實現對延遲郵件的再投遞控制:queue_run_delay:設置隊列管理進行掃描deferred郵件隊列的頻率,缺省值為1000秒。maximal_queue_lifetime:設置postfix在放棄投遞而返回不可投遞信息前,被延遲郵件再deferred郵件隊列中的生存時間。minimal_backoff_time:當一封郵件投遞失敗後,郵件隊列將在一段時間內忽視該郵件的存在,也就是我們前面講的時間郵票。該參數就是用來設置最小的時間郵票。缺省值為1000秒。maximal_backoff_time:設置最大的時間郵票。
6. 對拒絕服務攻擊的處理postfix對每一個SMTP會話都設置一個錯誤計數器,當該客戶端的請求未被接受或違反那UCE規則時,該計數器就增1。隨著計數器的增加,postfix將採取不同的措施來防止惡意用戶的拒絕服務攻擊。smtpd_error_sleep_time:當該錯誤計數器的值還很小時,postfix將暫停smtpd_error_sleep_time指定的時間,然後向客戶端報告一個錯誤。該參數的缺省值為5秒。smtpd_soft_error_limit:當錯誤計數器的值超過該參數指定的值時,postfix在響應該客戶端請求前將沉睡一段時間。缺省值為10。smtpd_hard_error_limit:當錯誤計數器的值超過該參數指定的值時,postfix中斷同該客戶端的連接。缺省值為100。
郵件系統postfix安裝與配置(二)
4.5 postfix對使用資源的控制
通過特定的postfix配置參數,我們可以實現postfix運行時對所消耗的資源的靈活控制。可以通過以下幾個方面來控制postfix消耗的資源:
1. 限制內存中的對象的大小要控制對內存資源的消耗,必須控制內存中對象的大小。可以用以下的參數來進行對象大小的控制:line_length_limit:控制讀入數據時每一行的大小,如果太長則強行將其分割成更短的行,太長的行在投遞時再重組。缺省值為2048 bytes。header_size_limit:限制信頭長度。缺省值為102400bytes。message_size_limit:限制postfix隊列文件的大小。缺省值為10240000 bytes。queue_minfree:郵件隊列中可用的空間大小。缺省為無限制。建議該值最好時message_size_limit的數倍以便於處理大郵件。bounce_size_limit:限制某一郵件不可投遞時,返回給發件人不可投遞報告的大小,缺省值為50000 bytes。
2. 限制內存中對象的數目qmgr_message_recipient_limit:設置內存中收件人地址的最大數目。缺省值為10000。qmgr_message_active_limit:設置active郵件隊列中郵件數目的最大值。缺省值為1000。duplicate_filter_limit:設置需要local和cleanup後台程序記住的收件人地址的最大數目。缺省值為1000。
3.限制等待一個外部命令完成的時間command_time_limit:設置local程序等待一個外部命令完成的時間。缺省值為1000秒。
4. 限制文件鎖定的操作時間deliver_lock_attempts:設置鎖定一個文件的最大嘗試次數。缺省值為5次。deliver_lock_delay:設置如果鎖定一個文件失敗後再次嘗試的等待時間,缺省值為1秒。
5. 控制錯誤恢復在某些情況下(如高負載),postfix的某個進程可能會死掉,這時master進程會試圖重新啟動該進程,我們可以通過下面的參數來控制這種行為:fork_attempts:試圖重啟動一個進程的最大嘗試次數。缺省值為5次。fork_delay:每兩次嘗試之間的等待時間,缺省值為1秒。transport_retry_time:隊列管理進程每兩次嘗試連接一個不正常的投遞代理進程之間的等待時間。缺省為60秒。
4.6 postfix中的地址操作
1. 將地址改寫為標準格式在cleanup進程進行表查詢之前,它首選請求trivial-rewrite進程將新郵件地址改寫成標準的user@fully.qualified.domain格式。改寫的目的是為了減少查詢表中的條目,從而提供查詢的效率。trivial-rewrite進程可以實現以下的地址改寫:* 將包含源路由信息的地址?a href="mailto@hosta">p@hosta,@hostb:user@site寫成user@site,因為postfix不支持包含源路由信息的地址格式。* 將形如user%domain的地址改寫成user@domain的形式。該特性可通過allow_percent_hack參數進行控制,其缺省值為yes。* 將只包含user的地址改寫成user@$myorigin。該特性可通過append_at_myorigin參數進行控制,其缺省值為yes。最好不要改動其缺省值,因為大多數的postfix進程更擅長處理地址形如user@$myorigin的郵件。* 將形?a href="mailtouser@host">puser@host的地址改寫成user@host.$mydomain。該特性可通過append_dot_mydomain參數進行控制,其缺省值為yes。* 將形?a href="mailtouser@site.">puser@site.的地址改寫成 user@site,也即除去了最後的點號。
2. 規范地址映射在cleanup進程將一封新郵件存入incoming郵件隊列之前,cleanup進程將根據查詢規范表來進行地址改寫,從而使之更具可讀性。主要是替換形如Firstname.Lastname 風格的地址以及清除無效的域。缺省postfix是不進行規范地址改寫的,你可以通過指定canonical_maps參數的值來使其生效。如:canonical_maps = hash:/etc/postfix/canonical也可以分別為收件人和發件人地址分別指定不同的改寫規范,這時參數sender_canonical_maps和recipient_canonical_maps的優先級比canonical_maps高。如:sender_canonical_maps = hash:/etc/postfix/sender_canonicalrecipient_canonical_maps = hash:/etc/postfix/recipient_canonical
3. 地址欺騙就是將形?a href="mailtouser@host.domain">puser@host.domain的地址改寫成user@domainuser@other.domain,好像是從其他的郵件服務器發出的一樣。缺省該功能是被禁止的,可以用參數masquerade_domains使其生效,如:masquerade_domains = $mydomain也可以通過masquerade_exceptions參數對特定的用戶不進行地址欺騙,如:masquerade_exceptions = root注意:地址欺騙只對發件人地址有作用。
4. 虛擬地址映射在運用了規范地址映射和地址欺騙之後,cleanup將使用虛擬表映射將郵件重定向到所有的收件人。注意,該操作僅僅作用於信頭上的收件人地址。這樣,我們就可以將發送到虛擬域的郵件投遞到真實用戶的郵箱。系統的別名數據庫同樣可以起到相同的作用。缺省該功能是被禁止的,可以用參數virtual_maps使其生效,如:virtual_maps = hash:/etc/postfix/virtual
5. Relocated數據庫查詢Relocated表格提供如何將郵件發送給在系統中沒有帳號的用戶。缺省該功能是被禁止的,可以用參數relocated_maps使其生效,如:relocated_maps = hash:/etc/postfix/relocated
6. 別名數據庫查詢當郵件在本地投遞時,local投遞代理進程會在別名數據庫(linux下為/etc/aliases)中查詢收件人的別名。該操作不會作用於郵件信頭中的地址。可以用alias_maps指定使用的別名數據庫。缺省地,該功能是有效的,如:alias_maps = hash:/etc/aliases可以通過alias_database參數控制別名數據庫的路徑,如:alias_database = hash:/etc/aliases
五、 postfix的配置實例
5.1為撥號用戶配置postfix假設有一個小公司使用撥號上網,公司通過ISP的SMTP服務器(假設其域名為mail.isp.com,ip地址為201.110.1.100)發送郵件;公司內部的員工通過公司的SMTP服務器(運行postfix)收發郵件,下面我們一起來配置公司內部的SMTP服務器。
1. 因為沒有自己的固定ip和域名,所以必須指定ISP的SMTP服務器作為郵件網關(智能主機)。可以用如下的參數指定:relayhost = [201.110.1.100]注意:relayhost的值可以是domain、host、hostort、[address]或[addressort]。
2. 當接收到新郵件時,postfix就會嘗試投遞該郵件。如果將該公司內部的SMTP服務器設置為按需撥號,也就是一有程序請求外聯就撥號,則會增加上網的費用。這時我們可以通過postfix的defer_transports參數推遲投遞新郵件直到postfix提出明確的要求,如指定:defer_transports = smtp這時如果我們在ppp的腳本(如/etc/ppp/ip-up.local)加上如下命令,則postfix只在撥號成功後投遞新郵件:/usr/sbin/sendmail
3. 因為我們是將郵件轉發到郵件網關(201.110.1.100)而不是自己進行投遞,所以我們沒有必要使用DNS,因此我們通過如下的參數取消DNS查詢:disable_dns_lookups = yes
4. 為了保証我們能收到回信,我們必須進行域偽裝。masquerade_domains = isp.com
下面就是我們的配置文件mail.cf:
#指定郵件網關relayhost = [201.110.1.100]# 在撥號成功後才投遞郵件defer_transports = smtp#取消DNS查詢disable_dns_lookups = yes#一般常規配置queue_directory = /var/spool/postfixprogram_directory = /usr/libexec/postfixcommand_directory = /usr/sbindaemon_directory = /usr/libexec/postfixmail_owner = postfixdefault_privs = nobodymail_spool_directory = /var/spool/mailmailbox_command = /usr/bin/procmaillocal_destination_concurrency_limit = 2default_destination_concurrency_limit = 10debug_peer_level = 2debugger_command=PATH=/usr/bin:/usr/X11R6/bin,xxgdb$daemon_directory/$ process_name $process_id & sleep 5# 假設本地網絡為192.168.1.1/24mynetworks = 192.168.1.1/24# host specific informationmyhostname = yourhost.isp.commydomain = local.isp.commyorigin = $mydomainwhere do we receive mail and who do we accept/receive mail for?inet_interfaces = allmydestination = $myhostname, localhost.$mydomain, $mydomaindefault_transport = smtpmasquerade_domains = isp.com
需要注意的是:這裡的$mydomain、$myorigin、$mydestination不能為isp.com, 因為你如果設定為isp.com,內部SMTP服務器就會認為你的郵件是轉發給它的,故而在本地嘗試投遞郵件,結果只會返回“unknown user”的錯誤。其次,該配置只實現了將郵件通過SMTP發送到ISP的SMTP服務器的手段,缺乏從ISP的郵件服務器取信的方法,這一點就只能通過如outlook或foxmail等的mail客戶端軟件來實現了。
5.2為中小型企業用戶配置postfix假設有一家數千名員工的公司,該公司通過租用專線上網。現在公司決定通過postfix來建立自己的郵件系統。在這裡我們假設該公司的域為some.com, 郵件服務器的域名mail.some.com,地址為202.200.180.2,DNS服務器的域名為dns.some.com,地址為 202.200.180.1。1. 配置DNS服務器,設置MX記錄指向mail.some.com。相關的配置文件為/var/named/some.com(假設其zone文件就叫some.com, 有關DNS配置的內容請參看本書的相關章節)的內容如下:
@ IN SOA dns.some.com. root.dns.some.com (2000011307 ; serial28800 ; refresh, seconds14400 ; retry, seconds3600000 ; expire, seconds86400 ; minimum, seconds)
@ IN NS dns.some.com.@ IN A 202.200.180.1@ IN MX 10 mail.some.com.
localhost IN A 127.0.0.1dns IN A 202.200.180.1mail IN A 202.200.180.2host1 IN A 202.200.180.3host2 IN A 202.200.180.4
2. 配置postfix,其配置文件及相關的解釋如下:
#設置一般的路徑信息queue_directory = /var/spool/postfixcommand_directory = /usr/sbindaemon_directory = /usr/libexec/postfixmail_spool_directory = /var/spool/mail
#設置郵件及郵件隊列的所有者為postfixmail_owner = postfix
#設置郵件服務器的主機名myhostname = mail.some.com
#設置mydomain、myorigin和mydomain參數mydomain = some.commyorigin =$mydomainmydestination = $mydomain
#設置postfix服務監聽的端口inet_interfaces = all
#設置本地收件人的用戶名查詢手段,缺省是查詢/etc/passwd文件#和別名數據庫local_recipient_maps = $alias_maps unixasswd.bynamealias_maps = hash:/etc/aliasesalias_database = hash:/etc/aliases
#設置最終的本地投遞代理程序,在這裡我們使用流行的procmailmailbox_command = /usr/bin/procmail
#設置該值為$mydomain以便客戶端的連接relay_domains = $mydomainmynetworks = 202.200.180.0/24
#設置向用戶顯示的主機名和版本信息smtpd_banner = $myhostname ESMTP $mail_name
#對於並發進程的限制,保持系統缺省值就可以滿足要求了。local_destination_concurrency_limit = 2default_destination_concurrency_limit = 10
#如果你不知道你在做什麼,最好不要改變下面的設置debug_peer_level = 2debugger_command =PATH=/usr/bin:/usr/X11R6/binxxgdb $daemon_directory/$process_name $process_id & sleep 5
3. 在RedHat中我們通常使用imap作為pop3服務器,可以通過rpm -q imap命令查看系統有沒有安裝imap。如果沒有安裝則插入linux光盤,用rpm -ivh imap-4.5-4.rpm 進行安裝。
4. 缺省地,pop3服務器是由inet 啟動的,所以必須去掉/etc/inetd.conf文件中有關pop3的一行注釋。如下所示:pop-3 stream tcp nowait root /usr/sbin/ipop3d ipop3d
5. 重新啟動inet服務器,啟動postfix:#/etc/rc.d/init.d/inet restart#postfix start
5.3在防火牆內部配置postfix假設一公司通過租用專線上網,公司內部使用192.168.0.0的私有ip, 然後通過防火牆(雙宿主主機)的ip欺騙上網,公司的郵件服務器(mail.some.com)也在內部網中,也使用私有ip。我們假設在防火牆上進行了端口轉發,可以將Internet對防火牆25端口的請求包轉發到內部的郵件服務器上,並且運行DNS服務的防火牆的MX記錄指向防火牆本身。在這個例子中,我想著重說明的是有關映射文件的用法。main.cf配置文件和相關的解釋如下所示:
#表明自己的身份myhostname = mail.some.commydomain = some.commydestination = $mydomain, $myhostname, localhost.$mydomainmyorigin = $mydomain#讓postfix監聽所有接口inet_interfaces = all
#通過mynetworks參數接受內部網用戶的SMTP連接請求mynetworks = 192.168.0.0/8
#向postfix管理員報告的信息量notify_classes = resource, software, bounce, policy
#如果客戶端的ip地址符合$maps_rbl_domains參數中列出的則拒絕之maps_rbl_domains = rbl.maps.vix.com, dul.maps.vix.com
#對可以連接的客戶端進行嚴格的限制smtpd_client_restrictions =#客戶端ip符合$mynetworks定義的范圍則接受連接permit_mynetworks,#根據access的查詢結果判斷客戶端連接的合法性check_client_access hash:/etc/postfix/access,#拒絕ip符合$maps_rbl_domains定義范圍的連接reject_maps_rbl,#如果客戶端在DNS中沒有記錄則拒絕連接,要慎用reject_unknown_hostname
#通過發件人的地址進行限制smtpd_sender_restrictions =permit_mynetworks,check_sender_access hash:/etc/postfix/access
#設置虛擬主機數據庫,別忘了執行"postmap virtual"進行格式轉換virtual_maps = hash:/etc/postfix/virtual
#對無系統帳號的郵件進行轉發設置,如離開公司的員工relocated_maps = hash:/etc/postfix/relocated
#設置別名數據庫alias_maps = hash:/etc/postfix/aliases
# 我們使用smtp投遞代理default_transport = smtp
# 一些常規設置mail_owner = postfixdefault_privs = nobody
#設置路徑信息queue_directory = /var/spool/postfixprogram_directory = /usr/libexec/postfixcommand_directory = /usr/sbindaemon_directory = /usr/libexec/postfixmail_spool_directory = /var/spool/mailmailbox_command = /usr/bin/procmail
#並發連接設置local_destination_concurrency_limit = 2default_destination_concurrency_limit = 10
然後,我們執行以下命令:
#進入postfix配置目錄cd /etc/postfix#用newaliases初始化別名數據庫newaliases#用postmap分別建立virtual、access和relocated查詢數據庫postmap virtualpostmap accesspostmap relocated#啟動postfix/etc/rc.d/init.d/postfix start
現在我們來看看virtual、access和reloacted幾個查詢文件的格式,下面是這幾個文件的示例和注釋:
#virtual文件示例#假設在這個例子中我們有個虛擬域為other.comother.com
#access 文件示例#如果符合前面的條件則進行後面操作,可以有三種操作:#1. [45]XX $messag:拒絕接受並且向客戶端顯示預定義的信息#2. REJECT:拒絕接受,不顯示信息#3. OK允許連接ispy99@noman.com.cn 550 Go awayfriend.com OK202.192 REJECT
#relocated 文件示例#該文件主要是將發給無系統帳號的郵件進行轉發who@some.com onetwo@newone.com
六、 postfix中的命令行工具及其它
下面我們來看一看postfix的命令行工具,通過這些工具的使用可能會使你對postfix的管理更簡單。
6.1 sendmail兼容的命令行工具
1. mailq 對郵件隊列文件進行列表。表中的每一個條目包含有以下信息:隊列文件ID、郵件的大小、到達的時間、發件人、收件人和投遞延遲的原因(如果投遞有延遲的話)。該命令主要是與showq後台程序通信來獲取隊列文件的相關信息。該命令無參數。
2. newaliases 該工具進行別名數據庫的初始化。如果沒有指定數據庫的類型,則使用系統默認的數據庫類型(在linux下為hash)。該命令可以不帶參數執行。
6.2 postfix自帶的命令行工具
1. postcat 打印郵件隊列文件的內容。後面界要顯示的隊列文件名,可以帶一個-v的參數進行冗余顯示。
2. postconf 打印配置參數設置後的值或postfix的其他信息。-d 打印配置參數的缺省值。-m 列出所有支持的查詢表類型。不帶參數則打印配置參數設置後的值。
3. postmap 建立postfix查詢數據庫。在linux下可以直接跟上原始文件而不帶任何參數來建立該數據庫。
6.3 postfix的日志postfix的日志文件位於/etc/log/maillog, 文件中包含有postfix的啟動信息、出錯信息以及同其他SMTP服務器的會話等等。如下所示:
Sep 10 05:54:17 mail postfix/smtpd[5072]: disconnect from unknown[204.140.244.150]Sep 10 06:06:00 mail postfix/qmgr[467]: 50D403DF8: from=, size=6591 (queue active)Sep 10 06:11:06 mail postfix/smtp[5085]: connect to bjmx2.163.net[202.108.255.241]: read timeout (port 25)Sep 10 06:16:07 mail postfix/smtp[5085]: connect to bjmx3.163.net[202.108.255.242]: read timeout (port 25)Sep 10 06:21:08 mail postfix/smtp[5085]: connect to bjmx1.163.net[202.108.255.240]: read timeout (port 25)
6.4 在postfix中使用MySQL數據庫Scott Cotton 和 Joshua Marcus寫了一段可以在postfix中添加mysql映射類型的代碼,從而我們可以將postfix查詢的別名數據庫等數據存儲在mysql數據庫中,讓postfix進行mysql查詢來得到結果。這樣做將有助於提供postfix的運行效率, 有其對需要不斷對映射數據的站點特別有用。
1.為postfix添加識別mysql數據庫映射的功能a. 由於這段代碼使用了mysql客戶端庫,所以我們必須安裝mysql的開包。可以到www.redhat.com等linux相關站點下載mysql?/a>}發包,也可以從某些linux的資源光盤中取得mysql的開發包,如MySQL-client-3.22.30-1.i386.rpm。b. 安裝該開發包:rpm -ivh MySQL-client-3.22.30-1.i386.rpmc. 下載postfix的源代碼包,根據本章“3.1源代碼包的安裝”的提示進行安裝,但是注意在執行make命令之前先執行以下命令:make -f Makefile.init makefiles CCARGS=-DHAS_MYSQL -I /usr/include/mysqlAUXLIBS=/usr/lib/mysql/libmysqlclient.a -lm
6.5. 配置postfix使用mysql數據庫映射我們以alias_maps進行說明。在main.cf中指定:alias_maps = mysql:/etc/postfix/mysql-aliases.cf
6.6 編輯mysql-aliases.cf
#首先指定登錄到mysql服務器的用戶名和密碼user = your_user_namepassword = your_password
#連接的數據庫名稱dbname = your_database_name
#查詢的表名table = mytable
#添加表的字段名稱#forward_addr為轉發地址#alias為別名數據select_field=forward_addrwhere_field=alias#添加附加的查詢條件additional_conditions=and status=paid
#指定要連接的MySQL服務器hosts=your.mysql.server
這樣,當發生一個查詢的時候,postfix是以這樣的SQL語句進行查詢的:select forward_addr from mytable where alias=$lookup and status=paid