<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SpaLinux.com - สปาลีนุกซ์ &#187; Mail</title>
	<atom:link href="http://spalinux.com/category/mail/feed" rel="self" type="application/rss+xml" />
	<link>http://spalinux.com</link>
	<description>เพื่อชีวิตที่ผ่อนคลายของคนใช้ลีนุกซ์</description>
	<lastBuildDate>Sat, 12 May 2012 10:38:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>เปลี่ยนคอนฟิก mailbox เป็น Maildir</title>
		<link>http://spalinux.com/2011/01/change_mailbox_location_to_maildir</link>
		<comments>http://spalinux.com/2011/01/change_mailbox_location_to_maildir#comments</comments>
		<pubDate>Mon, 03 Jan 2011 09:32:46 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[mailbox]]></category>
		<category><![CDATA[Maildir]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1217</guid>
		<description><![CDATA[โดยดีฟอลต์ของโปรแกรมรับส่งเมล์ เช่น postfix เมื่อได้รับเมล์แล้ว จะแยกเป็นไฟล์ตามชื่อ user เก็บไว้ในไดเรคทอรี /var/spool/mail/ หรือ /var/mail/ (soft link) ในบทความนี้จะกล่าวถึงการแก้ไขคอนฟิกที่อยู่ไฟล์ mailbox ของ postfix และ dovecot ให้เก็บเป็นรูปแบบ Maildir ไว้ใน  home ของ user (qmail-style) คอนฟิก Maildir ของ postfix คอนฟิกของ postfix ที่ระบุที่อยู่ mailbox คือ &#8220;home_mailbox&#8221; ซึ่งดีฟอลต์คือ Mailbox หมายถึงเก็บไฟล์ mailbox ของ user ในรูปแบบ /var/spool/mail/user การแก้ไขคอนฟิกให้เก็บเมล์ไว้แบบ Maildir ใน home ของ user  home_mailbox = Maildir/ รันคำสั่ง service เพื่อรีโหลดเซอร์วิส [...]]]></description>
			<content:encoded><![CDATA[<p>โดยดีฟอลต์ของโปรแกรมรับส่งเมล์ เช่น postfix เมื่อได้รับเมล์แล้ว จะแยกเป็นไฟล์ตามชื่อ user เก็บไว้ในไดเรคทอรี /var/spool/mail/ หรือ /var/mail/ (soft link)</p>
<p>ในบทความนี้จะกล่าวถึงการแก้ไขคอนฟิกที่อยู่ไฟล์ mailbox ของ postfix และ dovecot ให้เก็บเป็นรูปแบบ Maildir ไว้ใน  home ของ user (qmail-style)</p>
<h4><span id="more-1217"></span>คอนฟิก Maildir ของ postfix</h4>
<p>คอนฟิกของ postfix ที่ระบุที่อยู่ mailbox คือ &#8220;home_mailbox&#8221; ซึ่งดีฟอลต์คือ Mailbox หมายถึงเก็บไฟล์ mailbox ของ user ในรูปแบบ /var/spool/mail/user</p>
<p>การแก้ไขคอนฟิกให้เก็บเมล์ไว้แบบ Maildir ใน home ของ user </p>
<pre>home_mailbox = <strong><span style="color: #0000ff;">Maildir/</span></strong></pre>
<p>รันคำสั่ง service เพื่อรีโหลดเซอร์วิส postfix ให้คอนฟิกใหม่มีผล</p>
<pre>[root@fc14-64a ~]# <strong>service postfix reload
</strong>Reloading postfix:                                         [  OK  ]</pre>
<p>ล็อกอินด้วย user1 ทดสอบส่งเมล์ไปยัง user2</p>
<pre>[user1@fc14-64a ~]$ <strong>mail user2
</strong>Subject: test maildir format
.
EOT
Null message body; hope that's ok</pre>
<p>เปลี่ยนเป็นล็อกอินด้วย user2 สังเกตดู จะเห็นว่ามีไดเรคทอรี Maildir/ ถูกสร้างขึ้นใน home</p>
<pre>[user2@fc14-64a ~]$ <strong>ls -l
</strong>total 0
drwx------ 5 user2 user2 36 Jan  3 06:17 <span style="color: #0000ff;">Maildir</span></pre>
<p>ลองใช้คำสั่ง mail เพื่ออ่านเมล์</p>
<pre>[user2@fc14-64a ~]$ <strong>mail</strong>
No mail for user2</pre>
<p>ไม่สามารถอ่านเมล์ได้ เป็นเพราะว่าคำสั่ง mail โดยดีฟอลต์จะไปอ่านไฟล์ mailbox จากค่าตัวแปร $MAIL จาก shell ของผู้ใช้</p>
<p>ตรวจสอบค่าตัวแปร $MAIL ใน shell</p>
<pre>[user2@fc14-64a ~]$ <strong>echo $MAIL
</strong>/var/spool/mail/user2</pre>
<p>การแก้ไข ต้องตั้งค่าตัวแปร MAIL ให้เป็นรูปแบบ Maildir</p>
<pre>[user2@fc14-64a ~]$ <strong>MAIL=Maildir/</strong></pre>
<p>หมายเหตุ ตอนตั้งค่าตัวแปรใน shell ไม่ต้องมีเครื่องหมาย $ นำหน้าตัวแปร</p>
<p>ใช้คำสั่ง mail อ่านเมล์อีกครั้ง จะสามารถอ่านได้</p>
<pre>[user2@fc14-64a ~]$ <strong>mail</strong>
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"Maildir/": 1 message 1 new
&gt;N  1 user1@spalinux.com    Mon Jan  3 06:17  17/530   "test maildir format"
&amp; <strong>exit</strong></pre>
<h4>คอนฟิก Maildir ของ dovecot</h4>
<p>โดยดีฟอลต์ของโปรแกรม dovecot จะเก็บในรูปแบบ Maildir อยู่แล้ว แต่ถ้ามีการเปลี่ยนแปลงไป สามารถแก้ไขคอนฟิก mail_location กลับได้ตามนี้</p>
<p>คอนฟิกไฟล์ของ dovecot คือ /etc/dovecot/dovecot.conf หรือ /etc/dovecot/conf.d/10-mail.conf (สำหรับเวอร์ชั่นใหม่)</p>
<pre>mail_location = <strong><span style="color: #0000ff;">maildir:~/Maildir</span></strong></pre>
<p>รีโหลดเซอร์วิส dovecot เพื่อให้คอนฟิกใหม่มีผล</p>
<pre>[root@fc14-64a ~]# <strong>service dovecot reload</strong>
Reloading Dovecot Imap:                                    [  OK  ]</pre>
<p>ทดสอบอ่านเมล์ด้วยการ telnet เข้าพอร์ต 110</p>
<pre>[user2@fc14-64a ~]$ <strong>telnet localhost 110
</strong>Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
<strong>USER user2</strong>
+OK
<strong>PASS password
</strong>+OK Logged in.
<strong>LIST
</strong>+OK 1 messages:
1 545
.
<strong>RETR 1</strong>
+OK 545 octets
Return-Path: &lt;user1@spalinux.com&gt;
X-Original-To: user2
Delivered-To: user2@spalinux.com
Received: by fc14-64a.spalinux.com (Postfix, from userid 501)
        id 75E8B5BA29; Mon,  3 Jan 2011 06:17:29 +0700 (ICT)
Date: Mon, 03 Jan 2011 06:17:29 +0700
To: user2@spalinux.com
Subject: test maildir format
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Message-Id: &lt;20110102231729.75E8B5BA29@fc14-64a.spalinux.com&gt;
From: user1@spalinux.com</pre>
<pre>=
.
<strong>QUIT</strong>
+OK Logging out.
Connection closed by foreign host.</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2010/12/install_postfix_on_fedora_14_part_1">ติดตั้ง postfix บน Fedora 14 ตอนที่ 1</a></li>
<li><a href="http://spalinux.com/2010/12/install_postfix_on_fedora_14_part_2">ติดตั้ง postfix บน Fedora 14 ตอนที่ 2</a></li>
<li><a href="http://spalinux.com/2011/01/install_and_configure_dovecot">ติดตั้งและคอนฟิก dovecot</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/01/change_mailbox_location_to_maildir/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ติดตั้งและคอนฟิก dovecot</title>
		<link>http://spalinux.com/2011/01/install_and_configure_dovecot</link>
		<comments>http://spalinux.com/2011/01/install_and_configure_dovecot#comments</comments>
		<pubDate>Mon, 03 Jan 2011 07:21:16 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[dovecot]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1214</guid>
		<description><![CDATA[จากที่ได้ติดตั้ง postfix ซึ่งเป็นโปรแกรมประเภท SMTP เพื่อรับส่งเมล์แล้ว ในบทความนี้จะอธิบายการติดตั้งและคอนฟิกโปรแกรม dovecot  เพื่อให้อ่านเมล์ที่รับมาจากโปรแกรม postfix ได้ เหตุผลที่เลือกโปรแกรม dovecot เพราะความปลอดภัยของโปรแกรม ความง่ายต่อการคอนฟิก และสนับสนุนโปรแกรมอ่านเมล์ทั้ง IMAP และ POP3 ในที่นี้จะทดลองบน Fedora 14 เพื่อให้ต่อเนื่องกับบทความการติดตั้ง postfix ติดตั้งโปรแกรม dovecot ไฟล์ rpm ของโปรแกรม dovecot มีอยู่ในแผ่นดีวีดีติดตั้ง Fedora 14 อยู่แล้ว สามารถ mount และติดตั้งจากแผ่นได้เลย ใช้คำสั่ง mount แผ่นดีวีดีอยู่ในไดเรคทอรี /media [root@fc14-64a ~]# mount /dev/dvd /media mount: block device /dev/sr0 is write-protected, mounting read-only [root@fc14-64a ~]# [...]]]></description>
			<content:encoded><![CDATA[<p>จากที่ได้ติดตั้ง postfix ซึ่งเป็นโปรแกรมประเภท SMTP เพื่อรับส่งเมล์แล้ว ในบทความนี้จะอธิบายการติดตั้งและคอนฟิกโปรแกรม dovecot  เพื่อให้อ่านเมล์ที่รับมาจากโปรแกรม postfix ได้</p>
<p>เหตุผลที่เลือกโปรแกรม dovecot เพราะความปลอดภัยของโปรแกรม ความง่ายต่อการคอนฟิก และสนับสนุนโปรแกรมอ่านเมล์ทั้ง IMAP และ POP3</p>
<p><span id="more-1214"></span>ในที่นี้จะทดลองบน Fedora 14 เพื่อให้ต่อเนื่องกับบทความการติดตั้ง postfix</p>
<h4>ติดตั้งโปรแกรม dovecot</h4>
<p>ไฟล์ rpm ของโปรแกรม dovecot มีอยู่ในแผ่นดีวีดีติดตั้ง Fedora 14 อยู่แล้ว สามารถ mount และติดตั้งจากแผ่นได้เลย</p>
<p>ใช้คำสั่ง mount แผ่นดีวีดีอยู่ในไดเรคทอรี /media</p>
<pre>[root@fc14-64a ~]# <strong>mount /dev/dvd /media
</strong>mount: block device /dev/sr0 is write-protected, mounting read-only</pre>
<pre>[root@fc14-64a ~]# cd /media/Packages/
[root@fc14-64a Packages]# ls -l dovecot*
-rw-r--r-- 12 root 101737 1937252 Aug 26 08:47 dovecot-2.0.1-1.fc14.x86_64.rpm</pre>
<p>ใช้คำสั่ง rpm เพื่อติดตั้งโปรแกรม dovecot</p>
<pre>[root@fc14-64a Packages]# <strong>rpm -ivh dovecot-2.0.1-1.fc14.x86_64.rpm
</strong>Preparing...                ########################################### [100%]
   1:dovecot                ########################################### [100%]</pre>
<h4>รันเซอร์วิส dovecot</h4>
<p>ใช้คำสั่ง service เพื่อรันเซอร์วิส dovecot</p>
<pre>[root@fc14-64a ~]# <strong>service dovecot start
</strong>Starting Dovecot Imap:                                     [  OK  ]</pre>
<p>หากรันได้ถูกต้อง จะมีโปรเซส dovecot รันขึ้นมาตามตัวอย่างผลลัพธ์ของคำสั่ง ps</p>
<pre>[root@fc14-64a ~]# <strong>ps -ef | grep dovecot
</strong>root      3177     1  0 02:53 ?        00:00:00 /usr/sbin/dovecot
dovecot   3179  3177  0 02:53 ?        00:00:00 dovecot/anvil
root      3180  3177  0 02:53 ?        00:00:00 dovecot/log
root      3182  3177  0 02:53 ?        00:00:00 dovecot/config</pre>
<p>ตรวจสอบพอร์ตประเภท POP3, IMAP ที่สตาร์ตขึ้นมา</p>
<pre>[root@fc14-64a ~]# <strong>netstat -an
</strong>Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:993                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:995                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN</pre>
<p>สามารถดูชื่อหมายเลขพอร์ตจากไฟล์ /etc/services</p>
<pre>pop3            110/tcp         pop-3           # POP version 3
imap            143/tcp         imap2           # Interim Mail Access Proto v2
imaps           993/tcp                         # IMAP over SSL
pop3s           995/tcp                         # POP-3 over SSL</pre>
<h4>ทดสอบอ่านเมล์ผ่าน telnet เข้าพอร์ต POP3</h4>
<p>รันเซอร์วิส postfix เพื่อรับส่งเมล์ (หากไม่ได้รันอยู่)</p>
<pre>[root@fc14-64a ~]# <strong>service postfix start
</strong>Starting postfix:                                          [  OK  ]</pre>
<p>ล็อกอินด้วย user1 ทดสอบส่งเมล์ให้ user2</p>
<pre>[user1@fc14-64a ~]$ <strong>mail user2
</strong>Subject: <strong>test send mail to user2
test
.
</strong>EOT</pre>
<p>เราสามารถใช้คำสั่ง telnet เข้าพอร์ต pop3 (110) เพื่ออ่านเมล์ผ่านโปรโตคอล pop3 ได้</p>
<p>คำสั่งที่ใช้คือ USER และ PASS เพื่อระบุ username และ password สำหรับล็อกอินเข้าอ่านเมล์ผ่าน pop3</p>
<p>หากระบุ USER หรือ PASS ไม่ถูกต้อง จะขึ้น &#8220;-ERR Authentication failed.&#8221;</p>
<p>หากต้องการออกจากคำสั่ง telnet เข้าพอร์ต 110 ให้ใช้คำสั่ง QUIT</p>
<pre>[user2@fc14-64a ~]$ <strong>telnet localhost 110
</strong>Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
<strong>USER user2
</strong>+OK
<strong>PASS wrong
</strong><span style="color: #ff0000;">-ERR Authentication failed.
</span><strong>QUIT
</strong>+OK Logging out
Connection closed by foreign host.
[user2@fc14-64a ~]$</pre>
<p>ระบุ USER และ PASS ได้ถูกต้อง</p>
<pre>[user2@fc14-64a ~]$<strong> telnet localhost 110
</strong>Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
<strong>USER user2
</strong>+OK
<strong>PASS password
</strong>Connection closed by foreign host.</pre>
<p>หลังจากระบุ USER และ PASS ได้ถูกต้อง แต่หลุดออกจากคำสั่ง telnet</p>
<p>การแก้ไขปัญหาโปรแกรมที่เกี่ยวกับเมล์ ไม่ว่าจะเป็น postfix หรือรวมทั้ง dovecot สามารถดูสาเหตุได้ในไฟล์ /var/log/maillog</p>
<pre>[root@fc14-64a ~]# <strong>tail /var/log/maillog
</strong>...
Jan  3 03:13:59 fc14-64a dovecot: pop3-login: Login: user=&lt;user2&gt;, method=PLAIN, rip=127.0.0.1, lip=127.0.0.1, mpid=3793, secured
Jan  3 03:13:59 fc14-64a dovecot: pop3(user2): <span style="color: #ff0000;">Error: user user2: Initialization failed: mail_location not set and autodetection failed: Mail storage autodetection failed with home=/home/user2
</span>Jan  3 03:13:59 fc14-64a dovecot: pop3(user2): Error: Invalid user settings. Refer to server log for more information.</pre>
<p>สาเหตุเป็นเพราะว่าโปรแกรม dovecot ไม่สามารถหาที่อยู่ไฟล์ mailbox (mail_location) ของ user2 ได้</p>
<h4>แก้ไขคอนฟิก mail_location</h4>
<p>เพื่อแก้ปัญหาการหา mailbox ของ user ไม่เจอ ต้องแก้ไขคอนฟิก mail_location ของ dovecot</p>
<p>ไฟล์คอนฟิกหลักของ dovecot คือ /etc/dovecot/dovecot.conf ในเวอร์ชั่นก่อนจะรวมอยู่ในไฟล์นี้ทั้งหมด แต่ในเวอร์ชั่นใหม่จะมีการแยกไฟล์ตามประเภทของคอนฟิกไว้ในไดเรคทอรี /etc/dovecot/conf.d/ อีกที</p>
<p>สำหรับคอนฟิก mail_location จะอยู่ในไฟล์ /etc/dovecot/conf.d/10-mail.conf</p>
<p>ดีฟอลต์ mailbox ที่ได้รับมาจากโปรแกรม postfix จะแยกเป็นไฟล์ตามชื่อ user อยู่ในไดเรคทอรี /var/spool/mail/</p>
<pre>[root@fc14-64a ~]# <strong>ls -l /var/spool/mail/
</strong>-rw-------. 1 root    root 7141 Jan  3 02:53 root
-rw-rw----  1 user1   mail    0 Jan  3 03:02 user1
-rw-rw----  1 user2   mail  575 Jan  3 03:03 user2</pre>
<p>ในที่นี้จะเปลี่ยนคอนฟิกของ dovecot เพื่อให้อ่าน mailbox จาก /var/spool/mail/ โดยเปลี่ยนคอนฟิกเป็น</p>
<pre>mail_location = mbox:~/mail:INBOX=/var/spool/mail/%u</pre>
<p>รีสตาร์ตเซอร์วิส dovecot เพื่อให้คอนฟิกใหม่มีผล</p>
<pre>[root@fc14-64a ~]# <strong>service dovecot restart
</strong>Stopping Dovecot Imap:                                     [  OK  ]
Starting Dovecot Imap:                                     [  OK  ]</pre>
<p>ทดสอบใช้คำสั่ง telnet เข้าพอร์ต 110 เพื่ออ่านเมล์ผ่าน pop3 อีกที</p>
<pre>[user2@fc14-64a ~]$ <strong>telnet localhost 110
</strong>Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
<strong>USER user2
</strong>+OK
<strong>PASS password
</strong><span style="color: #ff0000;">-ERR [IN-USE] Couldn't open INBOX: Internal error occurred</span>. Refer to server log for more information. [2011-01-03 03:30:04]
Connection closed by foreign host.</pre>
<p>ยังใช้ไม่ได้ เพราะ dovecot ไม่สามารถหา INBOX ได้ เนื่องจากการคอนฟิกที่เปลี่ยนไปนี้ จะอ่านไฟล์ INBOX ที่อยู่ในไดเรคทอรี mail ที่อยู่ใน home ของ user ด้วย (mbox:~/mail)</p>
<p>ตรวจสอบปัญหาที่เกิดขึ้นในไฟล์ /var/log/maillog</p>
<pre>[root@fc14-64a ~]# <strong>tail /var/log/maillog
</strong>...
Jan  3 03:30:04 fc14-64a dovecot: pop3-login: Login: user=&lt;user2&gt;, method=PLAIN, rip=127.0.0.1, lip=127.0.0.1, mpid=3887, secured
Jan  3 03:30:04 fc14-64a dovecot: pop3(user2): <span style="color: #ff0000;">Error: chown(/home/user2/mail/.imap/INBOX, -1, 12(mail)) failed: Operation not permitted (egid=502(user2), group based on /var/spool/mail/user2)
</span>Jan  3 03:30:04 fc14-64a dovecot: pop3(user2): <span style="color: #ff0000;">Error: mkdir(/home/user2/mail/.imap/INBOX) failed: Operation not permitted
</span>Jan  3 03:30:04 fc14-64a dovecot: pop3(user2): Error: Couldn't open INBOX: Internal error occurred. Refer to server log for more information. [2011-01-03 03:30:04]
Jan  3 03:30:04 fc14-64a dovecot: pop3(user2): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0</pre>
<p>เมื่อพยายามอ่านเมล์ครั้งแรกแล้ว โปรแกรมจะสร้างไฟล์ต่างๆ ที่จำเป็นอยู่ใน home ของผู้ใช้โดยอัตโนมัติ</p>
<p>ตัวอย่างไฟล์ที่สร้างขึ้น</p>
<pre>[user2@fc14-64a ~]$ <strong>find mail/
</strong>mail/
mail/.imap
mail/.imap/INBOX</pre>
<p>ทดลองอ่านเมล์ผ่าน telnet เข้าพอร์ต 110 อีกครั้ง</p>
<pre>[user2@fc14-64a ~]$ <strong>telnet localhost 110
</strong>Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
<strong>USER user2
</strong>+OK
<strong>PASS password
</strong>+OK Logged in.
<strong>LIST
</strong>+OK 1 messages:
1 540
.
<strong>RETR 1
</strong>+OK 540 octets
Return-Path: &lt;user1@spalinux.com&gt;
X-Original-To: user2
Delivered-To: user2@spalinux.com
Received: by fc14-64a.spalinux.com (Postfix, from userid 501)
        id 686DC5BA29; Mon,  3 Jan 2011 03:03:39 +0700 (ICT)
Date: Mon, 03 Jan 2011 03:03:39 +0700
To: user2@spalinux.com
Subject: test send mail to user2
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: &lt;20110102200339.686DC5BA29@fc14-64a.spalinux.com&gt;
From: user1@spalinux.com</pre>
<pre>test
.
<strong>QUIT</strong>
+OK Logging out.
Connection closed by foreign host.</pre>
<p>หากถูกต้อง หลังจากระบุ USER และ PASS ได้ถูกต้อง สามารถใช้คำสั่ง LIST เพื่อแสดงตัวเลขลำดับที่เมล์ และขนาดของเมล์แสดง</p>
<p>ใช้คำสั่ง RETR ตามด้วยลำดับที่เมล์ เพื่อแสดงรายละเอียดของเมล์นั้นๆ</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2010/12/install_postfix_on_fedora_14_part_1">ติดตั้ง postfix บน Fedora 14 ตอนที่ 1</a></li>
<li><a href="http://spalinux.com/2010/12/install_postfix_on_fedora_14_part_2">ติดตั้ง postfix บน Fedora 14 ตอนที่ 2</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/01/install_and_configure_dovecot/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ติดตั้ง postfix บน Fedora 14 ตอนที่ 2</title>
		<link>http://spalinux.com/2010/12/install_postfix_on_fedora_14_part_2</link>
		<comments>http://spalinux.com/2010/12/install_postfix_on_fedora_14_part_2#comments</comments>
		<pubDate>Fri, 31 Dec 2010 07:45:28 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Mail]]></category>
		<category><![CDATA[Postfix]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1211</guid>
		<description><![CDATA[จากเนื้อหาตอนที่แล้ว ติดตั้ง postfix บน Fedora 14 ตอนที่ 1 ในตอนที่ 2 นี้ จะแนะนำคอนฟิกพื้นฐานของ postfix ที่น่าจะเปลี่ยนเป็นอย่างน้อย เพื่อให้สามารถรันเป็นเมล์เซิร์ฟเวอร์ได้ โดยจะแสดงให้เห็นถึงความแตกต่างก่อนการเปลี่ยน และหลังการเปลี่ยนคอนฟิก ไฟล์คอนฟิกหลักของ postfix คือไฟล์ /etc/postfix/main.cf  ในแต่ละส่วนจะบอกถึงออปชั่นในการแก้ไขคอนฟิกให้ได้ตามต้องการ การแก้ไขไฟล์คอนฟิกทุกครั้ง ต้องมีการรีโหลด (reload) เซอร์วิส เพื่อให้คอนฟิกใหม่มีผล ยกเว้นบางคอนฟิกต้อง รีสตาร์ต (restart) เซอร์วิส postfix หลังจากการเปลี่ยน ตัวอย่างการใช้คำสั่ง service เพื่อรีโหลดเซอร์วิส postfix [root@fc14-64a ~]# service postfix reload Shutting down postfix:                                     [  OK  ] Starting postfix:                                          [  OK  ] คอนฟิก inet_interfaces [...]]]></description>
			<content:encoded><![CDATA[<p>จากเนื้อหาตอนที่แล้ว <a href="http://spalinux.com/2010/12/install_postfix_on_fedora_14_part_1">ติดตั้ง postfix บน Fedora 14 ตอนที่ 1 </a>ในตอนที่ 2 นี้ จะแนะนำคอนฟิกพื้นฐานของ postfix ที่น่าจะเปลี่ยนเป็นอย่างน้อย เพื่อให้สามารถรันเป็นเมล์เซิร์ฟเวอร์ได้ โดยจะแสดงให้เห็นถึงความแตกต่างก่อนการเปลี่ยน และหลังการเปลี่ยนคอนฟิก</p>
<p>ไฟล์คอนฟิกหลักของ postfix คือไฟล์ /etc/postfix/main.cf  ในแต่ละส่วนจะบอกถึงออปชั่นในการแก้ไขคอนฟิกให้ได้ตามต้องการ</p>
<p>การแก้ไขไฟล์คอนฟิกทุกครั้ง ต้องมีการรีโหลด (reload) เซอร์วิส เพื่อให้คอนฟิกใหม่มีผล ยกเว้นบางคอนฟิกต้อง รีสตาร์ต (restart) เซอร์วิส postfix หลังจากการเปลี่ยน</p>
<p><span id="more-1211"></span>ตัวอย่างการใช้คำสั่ง service เพื่อรีโหลดเซอร์วิส postfix</p>
<pre>[root@fc14-64a ~]# <strong>service postfix reload</strong>
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]</pre>
<h4>คอนฟิก inet_interfaces</h4>
<p>เนื่องด้วยความปลอดภัย ดีฟอลต์คอนฟิกจากการติดตั้ง จะอนุญาตให้เฉพาะตัวเครื่องเซิร์ฟเวอร์เอง (localhost) เท่านั้นที่สามารถส่งเมล์ได้ (SMTP)</p>
<p>คอนฟิกก่อนเปลี่ยน</p>
<pre>inet_interfaces = localhost</pre>
<p>ใช้คำสั่ง netstat เพื่อแสดงการเปิดพอร์ต TCP 25 (SMTP)</p>
<pre>[root@fc14-64a ~]# <strong>netstat -an | grep 25</strong>
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN</pre>
<p>จะเห็นว่าพอร์ต 25 รองรับจาก 127.0.0.1 (localhost) เท่านั้น</p>
<p>ใช้คำสั่ง telnet เพื่อทดสอบ TCP connection เข้าพอร์ค 25 ทาง localhost</p>
<pre>[root@fc14-64a ~]# <strong>telnet 127.0.0.1 25
</strong>Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 fc14-64a.spalinux.com ESMTP Postfix
<strong>QUIT</strong>
221 2.0.0 Bye
Connection closed by foreign host.</pre>
<p><strong>หมายเหตุ</strong> ใช้คำสั่ง QUIT เพื่อออกจากการ telnet เข้าพอร์ต</p>
<p>แต่ถ้าใช้คำสั่ง telnet จากเครื่องอื่น เข้าพอร์ต 25</p>
<pre>[root@client ~]$ <strong>telnet 192.168.1.1 25
</strong>Trying 192.168.1.1...
telnet: connect to address 192.168.1.1: Connection refused</pre>
<p>หากต้องการให้เครื่องอื่นสามารถส่งเมล์โดยใช้เครื่องเซิร์ฟเวอร์นี้เป็น SMTP ต้องเปลี่ยนคอนฟิก</p>
<p>เปลี่ยนคอนฟิก &#8220;inet_interfaces&#8221; เป็น &#8220;all&#8221;</p>
<pre>inet_interfaces = <strong><span style="color: #3366ff;">all</span></strong></pre>
<p>หลังจากเปลี่ยนคอนฟิก ลองรีโหลดเซอร์วิส</p>
<pre>[root@fc14-64a ~]# <strong>service postfix reload
</strong>Reloading postfix:                                         [  OK  ]</pre>
<p>ใช้คำสั่ง netstat เพื่อตรวจสอบพอร์ต 25 ที่เปิดอีกครั้ง ยังเหมือนเดิม</p>
<pre>[root@fc14-64a ~]# <strong>netstat -an | grep 25
</strong>tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN</pre>
<p>สำหรับคอนฟิก inet_interfaces ต้องรีสตาร์ต service เท่านั้น</p>
<pre>[root@fc14-64a ~]# <strong>service postfix restart
</strong>Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]</pre>
<pre>
[root@fc14-64a ~]# <strong>netstat -an | grep 25
</strong>tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN</pre>
<h4>คอนฟิก mynetworks</h4>
<p>หลังจากแก้คอนฟิก &#8220;inet_interfaces&#8221; แล้ว โดยดีฟอลต์ จะอนุญาตให้ส่ง mail จากเครื่องที่อยู่ subnet เดียวกับเซิร์ฟเวอร์เท่านั้น เช่น สมมติว่าเซิรฟ์เวอร์ IP คือ 192.168.1.1/24</p>
<p>เครื่องที่สามารถส่งเมล์เข้าเซิร์ฟเวอร์นี้ได้นอกจากเครื่องเซิร์ฟเวอร์เองคือ เครื่องที่มี IP อยู่ใน subnet 192.168.1.0/24</p>
<p>แนะนำให้เซ็ทค่าคอนฟิก &#8220;mynetworks_style&#8221; เป็น &#8220;subnet&#8221; แล้วระบุ &#8220;mynetworks&#8221; ที่อนุญาตเพิ่มเติมให้สามารถส่งเมล์ได้ เช่น อนุญาตให้จากเครื่อง 192.168.2.0/24 และ 192.168.3.0/24</p>
<pre>mynetworks_style = <strong>subnet
</strong>mynetworks = 192.168.2.0/24, 192.168.3.0/24</pre>
<h4>คอนฟิก mydestination</h4>
<p>โดยดีฟอลต์ postfix จะรับเมล์ที่ส่งมาโดยระบุโดเมนเป็นชื่อ localhost หรือชื่อเครื่อง (hostname) เท่านั้น</p>
<pre>[root@fc14-64a ~]# <strong>hostname</strong>
fc14-64a.spalinux.com</pre>
<p>คอนฟิกดีฟอลต์</p>
<pre>mydestination = $myhostname, localhost.$mydomain, localhost</pre>
<p>หากต้องการให้รับเมล์ที่ส่งมาเป็นโดเมนอื่นด้วยเช่น เป็นแบบ MX record ต้องแก้ไขคอนฟิกเป็น</p>
<pre>mydestination = $myhostname, localhost.$mydomain, localhost, <strong><span style="color: #3366ff;">$mydomain</span></strong></pre>
<p>รีโหลดเซอร์วิสหลังจากแก้ไขคอนฟิก</p>
<pre>[root@fc14-64a ~]# <strong>service postfix reload
</strong>Reloading postfix:                                         [  OK  ]</pre>
<p>ทดสอบส่งเมล์โดยระบุอีเมล์เป็นโดเมน</p>
<pre>[user1@fc14-64a ~]$ <strong>mail </strong><strong>user2@spalinux.com</strong>
Subject: <strong>test sending to mx domain</strong>
<strong>test
.
</strong>EOT</pre>
<p>ล็อกด้วย user2 แล้วอ่านเมล์</p>
<pre>[user2@fc14-64a ~]$ <strong>mail</strong>
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/user2": 1 message 1 new
&gt;N  1 user1@fc14-64a.spali  Fri Dec 31 14:20  18/617   "test sending to mx domain"
&amp; <strong>1</strong>
Message  1:
From <strong><span style="color: #3366ff;">user1@fc14-64a.spalinux.com</span></strong>  Fri Dec 31 14:20:10 2010
Return-Path: &lt;user1@fc14-64a.spalinux.com&gt;
X-Original-To: user2@spalinux.com
Delivered-To: user2@spalinux.com
Date: Fri, 31 Dec 2010 14:20:10 +0700
To: user2@spalinux.com
Subject: test sending to mx domain
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: user1@fc14-64a.spalinux.com
Status: R</pre>
<pre>test</pre>
<pre>&amp; <strong>exit</strong></pre>
<h4>คอนฟิก myorigin</h4>
<p>โดยดีฟอลต์หากไม่ได้ตั้งค่าอีเมล์แอดเดรสของผู้ส่ง โปรแกรม postfix จะสร้างชื่ออีเมล์แอดเดรสให้โดยอัตโนมัติ คือนำชื่อ user มาต่อท้ายด้วยชื่อ hostname ของเครื่อง ถ้าต้องการตั้งค่าดีฟอลต์เป็นแบบอื่น เช่นที่นิยมกันคือตามด้วยชื่อโดเมน MX record สามาถทำได้โดยแก้ไขคอนฟิก myorigin</p>
<p>คอนฟิกก่อนการเปลี่ยน</p>
<pre>#myorigin = $myhostname</pre>
<p>หลังการเปลี่ยน</p>
<pre>myorigin = $mydomain</pre>
<p>หลังการแก้ไข ทดสอบส่งเมล์จาก user1</p>
<pre>[user1@fc14-64a ~]$ <strong>mail </strong><strong>user2@spalinux.com</strong>
Subject: <strong>test config myorigin
test
.
</strong>EOT</pre>
<p>ล็อกเป็น user2 แล้วอ่านเมล์</p>
<pre>[user2@fc14-64a ~]$ <strong>mail</strong>
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/user2": 1 message 1 unread
&gt;U  1 <strong><span style="color: #3366ff;">user1@spalinux.com</span></strong>    Fri Dec 31 14:28  19/595   "test config myorigin"
&amp; 1
Message  1:
From <strong><span style="color: #3366ff;">user1@spalinux.com</span></strong>  Fri Dec 31 14:28:19 2010
Return-Path: &lt;user1@spalinux.com&gt;
X-Original-To: user2@spalinux.com
Delivered-To: user2@spalinux.com
Date: Fri, 31 Dec 2010 14:28:19 +0700
To: user2@spalinux.com
Subject: test config myorigin
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: <strong><span style="color: #3366ff;">user1@spalinux.com
</span></strong>Status: RO</pre>
<pre>test</pre>
<pre>&amp; <strong>exit</strong></pre>
<p>สังเกตว่า เมล์แอดเดรสที่ขึ้นใน From จะเปลี่ยนจาก hostname &#8220;fc14-64a.spalinux.com&#8221; เป็น domain &#8220;spalinux.com&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2010/12/install_postfix_on_fedora_14_part_2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ติดตั้ง postfix บน Fedora 14 ตอนที่ 1</title>
		<link>http://spalinux.com/2010/12/install_postfix_on_fedora_14_part_1</link>
		<comments>http://spalinux.com/2010/12/install_postfix_on_fedora_14_part_1#comments</comments>
		<pubDate>Sat, 11 Dec 2010 09:25:18 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Mail]]></category>
		<category><![CDATA[Postfix]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1201</guid>
		<description><![CDATA[ด้วยเหตุผลหลายประการ ไม่ว่าจะเป็นเรื่องการจัดการ การคอนฟิกง่าย ความเร็ว เรื่องความปลอดภัย ทำให้ผู้ใช้หลายคนเลือกที่จะติดตั้งและใช้งานโปรแกรม Mail Server ที่ชื่อ Postfix ทั้งที่ดีฟอลต์ของ Linux หรือ UNIX ส่วนใหญ่จะติดตั้งโปรแกรม sendmail มาให้แล้ว บทความนี้จะเป็นตอนแรก แสดงวิธีการติดตั้ง postfix บน Fedora 14 (x86_64) เพื่อนำไปคอนฟิกและใช้งานเป็น Mail Server ตอนต่อไป ติดตั้งไฟล์ rpm ของ Postfix ไฟล์ rpm สำหรับติดตั้งโปรแกรม postfix ไม่มีอยู่ในแผ่นติดตั้ง Fedora 14 ต้องดาวน์โหลดไฟล์เพิ่มเติมเองจาก Fedora 14 Everything (ดูในข้อมูลอ้างอิง) [root@fc14-64a everything]# rpm -ivh postfix-2.7.1-1.fc14.x86_64.rpm error: Failed dependencies:         libmysqlclient.so.16()(64bit) is [...]]]></description>
			<content:encoded><![CDATA[<p>ด้วยเหตุผลหลายประการ ไม่ว่าจะเป็นเรื่องการจัดการ การคอนฟิกง่าย ความเร็ว เรื่องความปลอดภัย ทำให้ผู้ใช้หลายคนเลือกที่จะติดตั้งและใช้งานโปรแกรม Mail Server ที่ชื่อ Postfix ทั้งที่ดีฟอลต์ของ Linux หรือ UNIX ส่วนใหญ่จะติดตั้งโปรแกรม sendmail มาให้แล้ว</p>
<p>บทความนี้จะเป็นตอนแรก แสดงวิธีการติดตั้ง postfix บน Fedora 14 (x86_64) เพื่อนำไปคอนฟิกและใช้งานเป็น Mail Server ตอนต่อไป</p>
<p><span id="more-1201"></span></p>
<h4>ติดตั้งไฟล์ rpm ของ Postfix</h4>
<p>ไฟล์ rpm สำหรับติดตั้งโปรแกรม postfix ไม่มีอยู่ในแผ่นติดตั้ง Fedora 14 ต้องดาวน์โหลดไฟล์เพิ่มเติมเองจาก Fedora 14 Everything (ดูในข้อมูลอ้างอิง)</p>
<pre>[root@fc14-64a everything]# <strong>rpm -ivh postfix-2.7.1-1.fc14.x86_64.rpm</strong>
error: Failed dependencies:
        libmysqlclient.so.16()(64bit) is needed by postfix-2:2.7.1-1.fc14.x86_64
        libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by postfix-2:2.7.1-1.fc14.x86_64</pre>
<p>หากพบ error แบบนี้ ต้องติดตั้ง mysql-libs ก่อน ซึ่งหาได้จากในแผ่นติดตั้ง Fedora 14</p>
<pre>[root@fc14-64a Packages]# <strong>rpm -ivh mysql-libs-5.1.51-2.fc14.x86_64.rpm
</strong>Preparing...                ########################################### [100%]
   1:mysql-libs             ########################################### [100%]</pre>
<p>แล้วลองติดตั้ง postfix อีกครั้ง</p>
<pre>[root@fc14-64a everything]# <strong>rpm -ivh postfix-2.7.1-1.fc14.x86_64.rpm
</strong>Preparing...                ########################################### [100%]
   1:postfix                ########################################### [100%]</pre>
<h4>เปลี่ยนคอนฟิก alternatives</h4>
<p>โปรแกรม Mail Server ที่ติดตั้งมาโดยดีฟอลต์กับ Fedora คือ sendmail ต้องปิดเซอร์วิสของ sendmail ก่อน ด้วยคำสั่ง service</p>
<pre>[root@fc14-64a ~]# <strong>service sendmail stop
</strong>Shutting down sm-client:                                   [  OK  ]
Shutting down sendmail:                                    [  OK  ]</pre>
<p>ใช้คำสั่ง chkconfig เพื่อปิดไม่ให้รันเซอร์วิส sendmail ตอนบู๊ตเครื่อง</p>
<pre>[root@fc14-64a ~]# <strong>chkconfig sendmail off</strong></pre>
<p>คุณสมบัติ alternative ช่วยอำนวยความสะดวกผู้ใช้งาน เมื่อมีการเปลี่ยนโปรแกรมประเภท Mail Server คือจะมีการสร้าง soft link จำลองไปยังโปรแกรมที่เปลี่ยนไป โดยที่ผู้ใช้งานยังเรียกคำสั่ง หรือ path หรือกระทั่ง man page ในการเรียกยังเหมือนเดิม เช่นยังคงใช้คำสั่ง mailq เหมือนเดิมแม้ว่าจะเปลี่ยนจาก sendmail ไปเป็น postfix แล้ว</p>
<pre>[root@fc14-64a ~]# <strong>ls -l /usr/bin/mailq</strong>
lrwxrwxrwx 1 root root 27 Dec 11 18:18 /usr/bin/mailq -&gt; /etc/alternatives/mta-mailq</pre>
<p>ก่อนเปลี่ยน soft link ต่างๆ จะถูกโยงไปยังโปรแกรมของ sendmail</p>
<pre>[root@fc14-64a ~]# <strong>cd /etc/alternatives/
</strong>[root@fc14-64a alternatives]# <strong>ls -l</strong>
total 0
lrwxrwxrwx. 1 root root 15 Nov  4 22:51 ld -&gt; /usr/bin/ld.bfd
lrwxrwxrwx  1 root root 27 Dec 11 18:09 mta -&gt; /usr/sbin/sendmail.sendmail
lrwxrwxrwx  1 root root 41 Dec 11 18:09 mta-aliasesman -&gt; /usr/share/man/man5/aliases.sendmail.5.gz
lrwxrwxrwx  1 root root 23 Dec 11 18:09 mta-mailq -&gt; /usr/bin/mailq.sendmail
lrwxrwxrwx  1 root root 39 Dec 11 18:09 mta-mailqman -&gt; /usr/share/man/man1/mailq.sendmail.1.gz
lrwxrwxrwx  1 root root 28 Dec 11 18:09 mta-newaliases -&gt; /usr/bin/newaliases.sendmail
lrwxrwxrwx  1 root root 44 Dec 11 18:09 mta-newaliasesman -&gt; /usr/share/man/man1/newaliases.sendmail.1.gz
lrwxrwxrwx  1 root root 24 Dec 11 18:09 mta-pam -&gt; /etc/pam.d/smtp.sendmail
lrwxrwxrwx  1 root root 23 Dec 11 18:09 mta-rmail -&gt; /usr/bin/rmail.sendmail
lrwxrwxrwx  1 root root 26 Dec 11 18:09 mta-sendmail -&gt; /usr/lib/sendmail.sendmail
lrwxrwxrwx  1 root root 42 Dec 11 18:09 mta-sendmailman -&gt; /usr/share/man/man8/sendmail.sendmail.8.gz
lrwxrwxrwx. 1 root root 33 Nov  4 22:53 xinputrc -&gt; /etc/X11/xinit/xinput.d/ibus.conf</pre>
<p>ใช้คำสั่ง alternatives เพื่อเปลี่ยน soft link ของคำสั่งเกี่ยวกับ Mail Server</p>
<pre>[root@fc14-64a alternatives]# <strong>alternatives --config mta</strong></pre>
<pre>There are 2 programs which provide 'mta'.</pre>
<pre>  Selection    Command
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.sendmail
   2           /usr/sbin/sendmail.postfix</pre>
<pre>Enter to keep the current selection[+], or type selection number: <strong>2</strong></pre>
<p>ใส่ค่าเลข 2 เพื่อเปลี่ยนจาก sendmail เป็น postfix</p>
<p>ตรวจสอบ soft link อีกครั้ง จะเห็นว่า soft link ต่างๆ ถูกโยงใหม่ไปยังโปรแกรม postfix แล้ว</p>
<pre>[root@fc14-64a alternatives]# <strong>ls -l
</strong>total 0
lrwxrwxrwx. 1 root root 15 Nov  4 22:51 ld -&gt; /usr/bin/ld.bfd
lrwxrwxrwx  1 root root 26 Dec 11 18:18 mta -&gt; /usr/sbin/sendmail.postfix
lrwxrwxrwx  1 root root 40 Dec 11 18:18 mta-aliasesman -&gt; /usr/share/man/man5/aliases.postfix.5.gz
lrwxrwxrwx  1 root root 22 Dec 11 18:18 mta-mailq -&gt; /usr/bin/mailq.postfix
lrwxrwxrwx  1 root root 38 Dec 11 18:18 mta-mailqman -&gt; /usr/share/man/man1/mailq.postfix.1.gz
lrwxrwxrwx  1 root root 27 Dec 11 18:18 mta-newaliases -&gt; /usr/bin/newaliases.postfix
lrwxrwxrwx  1 root root 43 Dec 11 18:18 mta-newaliasesman -&gt; /usr/share/man/man1/newaliases.postfix.1.gz
lrwxrwxrwx  1 root root 23 Dec 11 18:18 mta-pam -&gt; /etc/pam.d/smtp.postfix
lrwxrwxrwx  1 root root 22 Dec 11 18:18 mta-rmail -&gt; /usr/bin/rmail.postfix
lrwxrwxrwx  1 root root 25 Dec 11 18:18 mta-sendmail -&gt; /usr/lib/sendmail.postfix
lrwxrwxrwx  1 root root 41 Dec 11 18:18 mta-sendmailman -&gt; /usr/share/man/man1/sendmail.postfix.1.gz
lrwxrwxrwx. 1 root root 33 Nov  4 22:53 xinputrc -&gt; /etc/X11/xinit/xinput.d/ibus.conf</pre>
<p>รันเซอร์วิส postfix</p>
<pre>[root@fc14-64a ~]# <strong>service postfix start
</strong>Starting postfix:                                          [  OK  ]</pre>
<p>หากรันได้สำเร็จ ใช้คำสั่ง ps เพื่อดูโปรเซสของ postfix จะขึ้นตามนี้</p>
<pre>[root@fc14-64a ~]# <strong>ps -ef | grep postfix
</strong>root      1784     1  0 18:22 ?        00:00:00 /usr/libexec/postfix/master
postfix   1786  1784  0 18:22 ?        00:00:00 pickup -l -t fifo -u
postfix   1787  1784  0 18:22 ?        00:00:00 qmgr -l -t fifo -u</pre>
<p>ใช้คำสั่ง chkconfig เพื่อให้รันเซอร์วิส postfix ตอนบู๊ตเครื่อง</p>
<pre>[root@fc14-64a ~]# <strong>chkconfig postfix on</strong></pre>
<h4>ทดสอบส่ง mail ในเครื่องเซิร์ฟเวอร์เอง</h4>
<p>ในการทดสอบ ใช้คำสั่ง useradd เพื่อเพิ่ม user1 และ user2</p>
<pre>[root@fc14-64a ~]# <strong>useradd user1
</strong>[root@fc14-64a ~]# <strong>id user1
</strong>uid=501(user1) gid=501(user1) groups=501(user1)</pre>
<pre>[root@fc14-64a ~]# <strong>useradd user2
</strong>[root@fc14-64a ~]# <strong>id user2
</strong>uid=502(user2) gid=502(user2) groups=502(user2)</pre>
<p>สามารถใช้คำสั่ง mail เพื่อทดลองส่ง mail และอ่าน mail แบบง่ายๆ ได้ หากต้องการส่งก็พิมพ์คำสั่ง mail แล้วตามด้วย email address ปลายทาง หรือถ้าอยู่บนเครื่องเดียวกันก็ตามด้วยชื่อ username อย่างเดียวก็ได้</p>
<p>หลังจากพิมพ์คำสั่ง mail แล้วกด [enter] หน้าจอจะขึ้น Subject: เพื่อให้ใส่ข้อความสำหรับใช้เป็น Subject ของ mail แล้วกด [enter] จากนั้นจะเป็นเนื้อหาของ mail ที่พิมพ์ไปได้เรื่อยๆ</p>
<p>หากต้องการจบในส่วนเนื้อหาของ mail ให้กด [enter] ครั้งนึง แล้วพิมพ์เครื่องหมายจุด &#8220;.&#8221; ตัวเดียวแล้ว [enter] อีกครั้ง จะเป็นการสิ้นสุดการใช้คำสั่งเพื่อส่ง mail</p>
<p>ล็อกอินด้วย user1 เพื่อส่ง mail ไปหา user2</p>
<pre>[root@fc14-64a ~]# <strong>su - user1</strong>
[user1@fc14-64a ~]$ <strong>mail user2
</strong>Subject: <strong>test send mail using postfix #1</strong>
testing
<strong>.</strong>
EOT
[user1@fc14-64a ~]$</pre>
<p>ล็อกอินด้วย user2 เพื่ออ่าน mail</p>
<p>พิมพ์คำสั่ง mail โดยไม่ต้องตามด้วยอะไร เพื่ออ่าน mail ของ user ที่พิมพ์คำสั่ง หน้าจอจะขึ้นรายการ mail ขึ้นมา พร้อมตัวเลขกำกับ พิมพ์ตัวเลขของ mail ที่ต้องการอ่าน ก็จะขึ้น</p>
<p>เนื้อหาของ mail ฉบับนั้นๆ พร้อมด้วย mail header</p>
<p>พิมพ์อักษร &#8220;q&#8221; เพื่อออกจากคำสั่ง mail ในโหมดการอ่าน</p>
<pre>[root@fc14-64a ~]# <strong>su - user2
</strong>[user2@fc14-64a ~]$ <strong>mail</strong>
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/user2": 1 message 1 new
&gt;N  1 user1@fc14-64a.spali  Sat Dec 11 18:30  18/629   "test send mail using postfix #1"
&amp; <strong>1</strong>
Message  1:
From user1@fc14-64a.spalinux.com  Sat Dec 11 18:30:28 2010
Return-Path: &lt;user1@fc14-64a.spalinux.com&gt;
X-Original-To: user2
Delivered-To: user2@fc14-64a.spalinux.com
Date: Sat, 11 Dec 2010 18:30:28 +0700
To: user2@fc14-64a.spalinux.com
Subject: test send mail using postfix #1
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: user1@fc14-64a.spalinux.com
Status: R</pre>
<pre>testing</pre>
<pre>&amp; <strong>q</strong>
Held 1 message in /var/spool/mail/user2
[user2@fc14-64a ~]$</pre>
<p>รายละเอียดการส่ง mail พร้อม error ที่เกิดขึ้นกับโปรแกรมประเภท Mail Server จะถูกเก็บไว้ในไฟล์ /var/log/maillog ซึ่งสามารถนำมาใช้ในการแก้ปัญหาได้</p>
<p>ตัวอย่างของไฟล์ /var/log/maillog ที่เกิดขึ้น สำหรับการส่ง mail จาก user1 ไปยัง user2</p>
<pre>[root@fc14-64a ~]# <strong>tail /var/log/maillog
</strong>Dec 11 18:30:28 fc14-64a postfix/pickup[1786]: 3F5237385: uid=501 from=&lt;user1&gt;
Dec 11 18:30:28 fc14-64a postfix/cleanup[1839]: 3F5237385: message-id=&lt;20101211113028.3F5237385@fc14-64a.spalinux.com&gt;
Dec 11 18:30:28 fc14-64a postfix/qmgr[1787]: 3F5237385: from=&lt;user1@fc14-64a.spalinux.com&gt;, size=476, nrcpt=1 (queue active)
Dec 11 18:30:28 fc14-64a postfix/local[1841]: 3F5237385: to=&lt;user2@fc14-64a.spalinux.com&gt;, orig_to=&lt;user2&gt;, relay=local, delay=0.09, delays=0.04/0.05/0/0, dsn=2.0.0,status=sent (delivered to mailbox)
Dec 11 18:30:28 fc14-64a postfix/qmgr[1787]: 3F5237385: removed</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.postfix.org/" target="_blank">The Postfix Home Page</a></li>
<li><a href="http://www.mirror.in.th/osarchive/fedora/releases/14/Everything/x86_64/os/Packages/" target="_blank">Fedora 14 Everything</a></li>
<li><a href="http://www.server-world.info/en/note?os=Fedora_11&amp;p=mail&amp;f=" target="_blank">Server World &#8211; Fedora 11 &#8211; MAIL Server &#8211; Install Postfix</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2010/12/install_postfix_on_fedora_14_part_1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คอนฟิก sendmail เบื้องต้น</title>
		<link>http://spalinux.com/2009/11/basic_configure_sendmail</link>
		<comments>http://spalinux.com/2009/11/basic_configure_sendmail#comments</comments>
		<pubDate>Sun, 29 Nov 2009 17:17:51 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[sendmail]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1000</guid>
		<description><![CDATA[การติดตั้งและคอนฟิก Mail Server บนลีนุกซ์มีให้เลือกหลายโปรแกรม แต่ที่เป็นดีฟอลต์ของ distribution ส่วนใหญ่ และใช้งานกันมากที่สุดก็น่าจะเป็นโปรแกรม sendmail ในทีนี้ขอแนะนำพื้นฐานการคอนฟิก sendmail เพื่อให้สามารถรับและส่ง Mail ได้ โดยทดสอบกับ Fedora 12 รันเซอร์วิส sendmail ดีฟอลต์จากการติดตั้ง Fedora โปรแกรม sendmail จะถูกติดตั้งมาแล้ว หากเซอร์วิสยังไม่ถูกรัน สามารถใช้คำสั่ง service เพื่อเริ่มรันโปรแกรมได้ [root@fc12-64a ~]# service sendmail start Starting sendmail:                                         [  OK  ] Starting sm-client:                                        [  OK  ] ไฟล์ /var/log/maillog ช่วยในการตรวจสอบการรับส่ง Email และปัญหาที่อาจเกิดขึ้นคือไฟล์ ข้อความที่ขึ้นในไฟล์ /var/log/maillog เมื่อเริ่มรันเซอร์วิส [root@fc12-64a ~]# tail /var/log/maillog [...]]]></description>
			<content:encoded><![CDATA[<p>การติดตั้งและคอนฟิก Mail Server บนลีนุกซ์มีให้เลือกหลายโปรแกรม แต่ที่เป็นดีฟอลต์ของ distribution ส่วนใหญ่ และใช้งานกันมากที่สุดก็น่าจะเป็นโปรแกรม sendmail</p>
<p>ในทีนี้ขอแนะนำพื้นฐานการคอนฟิก sendmail เพื่อให้สามารถรับและส่ง Mail ได้ โดยทดสอบกับ Fedora 12</p>
<p><span id="more-1000"></span></p>
<h4>รันเซอร์วิส sendmail</h4>
<p>ดีฟอลต์จากการติดตั้ง Fedora โปรแกรม sendmail จะถูกติดตั้งมาแล้ว หากเซอร์วิสยังไม่ถูกรัน สามารถใช้คำสั่ง service เพื่อเริ่มรันโปรแกรมได้</p>
<pre>[root@fc12-64a ~]# <strong>service sendmail start
</strong>Starting sendmail:                                         [  OK  ]
Starting sm-client:                                        [  OK  ]</pre>
<p>ไฟล์ /var/log/maillog ช่วยในการตรวจสอบการรับส่ง Email และปัญหาที่อาจเกิดขึ้นคือไฟล์</p>
<p>ข้อความที่ขึ้นในไฟล์ /var/log/maillog เมื่อเริ่มรันเซอร์วิส</p>
<pre>[root@fc12-64a ~]# <strong>tail /var/log/maillog
</strong>...
Nov 29 12:16:52 fc12-64a sendmail[1958]: starting daemon (8.14.3): SMTP+queueing@01:00:00
Nov 29 12:16:52 fc12-64a sm-msp-queue[1967]: starting daemon (8.14.3): queueing@01:00:00</pre>
<h4>ทดสอบการส่ง mail</h4>
<p>บน UNIX ส่วนใหญ่ รวมทั้ง Linux จะมีคำสั่ง mail เพื่อใช้ในการอ่าน และส่ง Email ไปยังผู้อื่นได้</p>
<p>เพื่อความง่าย จะทดสอบด้วยการสร้างผู้ใช้งานขึ้นมา 2 คน คือ &#8220;user1&#8243; และ &#8220;user2&#8243;</p>
<p>ล็อกอินด้วย user1 แล้วใช้คำสั่ง mail ระบุออปชั่น &#8216;-s&#8217; ใส่ Subject ของอีเมล์ เพื่อส่งไปยัง user2</p>
<p>พิมพ์ข้อความของ Email ที่ต้องการ หากจบข้อความให้พิมพ์เครื่องหมายจุด &#8220;.&#8221; เดียว ของบรรทัด แล้ว [Enter] คำสั่ง mail จะทำการส่ง Email</p>
<pre>[user1@fc12-64a ~]$ <strong>mail -s "subject testing 1" user2
Data messages
.
</strong>EOT</pre>
<p>ตัวอย่างไฟล์ /var/log/maillog ที่แสดง ว่า user1 ส่ง Email ไปยัง user2</p>
<pre>[root@fc12-64a ~]# <strong>tail /var/log/maillog
</strong>...
Nov 29 12:24:24 fc12-64a sendmail[2111]: nAT5OO5L002111: <span style="color: #0000ff;"><strong>from=user1</strong></span>, size=223,, nrcpts=1, msgid=&lt;200911290524.nAT5OO5L002111@fc12-64a.spalinux.com&gt;, relay=user1@localhost
Nov 29 12:24:24 fc12-64a sendmail[2112]: nAT5OOs6002112: from=&lt;user1@fc12-64a.spalinux.com&gt;, size=487,, nrcpts=1,msgid=&lt;200911290524.nAT5OO5L002111@fc12-64a.spalinux.com&gt;, proto=ESMTP, daemon=MTA, relay=localhost [127.0.0.1]
Nov 29 12:24:24 fc12-64a sendmail[2111]: nAT5OO5L002111: <span style="color: #0000ff;"><strong>to=user2</strong></span>, ctladdr=user1 (501/100), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30223,relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (nAT5OOs6002112 Message accepted for delivery)
Nov 29 12:24:24 fc12-64a sendmail[2113]: nAT5OOs6002112: to=&lt;user2@fc12-64a.spalinux.com&gt;, ctladdr=&lt;user1@fc12-64a.spalinux.com&gt; (501/100), delay=00:00:00,xdelay=00:00:00, mailer=local, pri=30693, dsn=2.0.0, stat=Sent
 
เปลี่ยนมาล็อกอินด้วย user2 ใช้คำสั่ง mail โดยไม่ต้องระบุออปชั่นใดๆ เพื่ออ่าน Email</pre>
<p>ในคำสั่ง mail สามารถใส่คำสั่ง เช่นในที่นี้ใส่ตัวเลข 1 ซึ่งหมายถึงต้องการอ่านรายละเอียด Email ฉบับที่ 1</p>
<pre>[user2@fc12-64a ~]$ <strong>mail</strong>
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/user2": 1 message 1 new
&gt;N  1 user1@localhost.loca  Sun Nov 29 12:24  20/790   "subject testing 1"
&amp; <strong>1</strong>
Message  1:
From user1@localhost.localdomain  Sun Nov 29 12:24:24 2009
Return-Path: &lt;user1@localhost.localdomain&gt;
From: user1@localhost.localdomain
Date: Sun, 29 Nov 2009 12:24:24 +0700
To: user2@localhost.localdomain
Subject: subject testing 1
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
Status: R</pre>
<pre>Data messages</pre>
<pre>&amp; <strong>q</strong>
Held 1 message in /var/spool/mail/user2</pre>
<p>พิมพ์ตัวอักษร q เมื่อต้องการออกจากคำสั่ง mail</p>
<h4>แก้ไขคอนฟิก SMTP Connection จากเครื่องอื่น</h4>
<p>คอนฟิกดีฟอลต์ จะอนุญาตให้ส่ง Email ระหว่าง user ที่อยู่ในเครื่องเดียวกันเท่านั้น ไม่รับ Email จากที่อื่น หรือ ไม่รองรับ SMTP Connection จากเครื่องอื่นๆ เลย</p>
<p>ตัวอย่างการทดสอบการเชื่อมต่อ SMTP Connect จากเครื่องอื่น จะเห็นว่าไม่สามารถเชื่อมต่อได้ ขึ้น &#8220;Connection refused&#8221;</p>
<p><strong>หมายเหตุ</strong> อย่าลืมตรวจสอบคอนฟิกของ firewall เช่น iptables ที่รันอยู่ด้วย ว่าเปิดพอร์ต SMTP หรือ TCP 25 อยู่หรือไม่</p>
<pre>[other1@client1 ~]$ <strong>telnet 192.168.1.1 25
</strong>Trying 192.168.1.1...
telnet: connect to address 192.168.1.1: Connection refused</pre>
<p>ไฟล์คอนฟิกหลักของ sendmail คือ /etc/mail/sendmail.cf แต่ไม่แนะนำให้แก้ไขไฟล์นี้โดยตรงเพราะความซับซ้อนของไฟล์ แนะนำให้แก้ไฟล์ /etc/mail/sendmail.mc</p>
<p>เช่น ต้องการแก้ไขคอนฟิกให้ sendmail รับ SMTP connection จากเครื่องอื่นๆ ด้วย</p>
<pre>[root@fc12-64a ~]# <strong>/etc/mail/sendmail.mc
</strong>dnl # The following causes sendmail to only listen on the IPv4 loopback address
dnl # 127.0.0.1 and not on any other network devices. Remove the loopback
dnl # address restriction to accept email from the internet or intranet.
dnl #
DAEMON_OPTIONS(`Port=smtp,<span style="color: #ff0000;">Addr=127.0.0.1,</span> Name=MTA')dnl</pre>
<p>แก้เป็น</p>
<pre>DAEMON_OPTIONS(`Port=smtp, Name=MTA')dnl</pre>
<p>หลังจากแก้ไขไฟล์ sendmail.mc เรียบร้อย ต้องรันคำสั่ง make เพื่อแปลงไฟล์ sendmail.mc ให้เป็นไฟล์ sendmail.cf</p>
<p>ในที่นี้หากต้องการเปรียบเทียบว่าไฟล์ sendmail.cf เปลี่ยนแปลงไปอย่างไรบ้าง ให้ copy สำรองไฟล์ของเดิมไว้</p>
<pre>[root@fc12-64a ~]# cd /etc/mail
[root@fc12-64a mail]# cp sendmail.cf sendmail.cf.orig
[root@fc12-64a mail]# ./make</pre>
<pre><span style="color: #ff0000;">WARNING: 'sendmail.mc' is modified. Please install package sendmail-cf to update your configuration.</span></pre>
<p>หากเจอข้อความ error แบบนี้ ต้องติดตั้งไฟล์ rpm เพิ่มเติม คือ sendmail-cf ซึ่งหาได้จากแผ่นดีวีดีติดตั้ง</p>
<pre>[root@fc12-64a ~]# <strong>cd /media/Packages/
</strong>[root@fc12-64a Packages]# <strong>rpm -i sendmail-cf-8.14.3-8.fc12.x86_64.rpm</strong></pre>
<p>ทดลองรันคำสั่ง make อีกครั้ง</p>
<pre>[root@fc12-64a ~]# <strong>cd /etc/mail
</strong>[root@fc12-64a mail]# <strong>./make</strong></pre>
<p>ไฟล์ sendmail.cf จะถูกปรับปรุงจากไฟล์ sendmail.mc</p>
<p>คำสั่ง diff แสดงการเปลี่ยนแปลงไฟล์</p>
<pre>[root@fc12-64a mail]# <strong>diff sendmail.cf.orig sendmail.cf
</strong>18a19,22
&gt; ##### built by root@fc12-64a.spalinux.com on Sun Nov 29 14:15:46 ICT 2009
&gt; ##### in /etc/mail
&gt; ##### using /usr/share/sendmail-cf/ as configuration include directory
&gt; #####
261c265
&lt; O DaemonPortOptions=Port=smtp,<span style="color: #ff0000;">Addr=127.0.0.1,</span> Name=MTA
---
&gt; O DaemonPortOptions=Port=smtp, Name=MTA</pre>
<p>ใช้คำสั่ง service เพื่อ รีสตาร์ตเซอร์วิส sendmail ใหม่อีกครั้ง</p>
<pre>[root@fc12-64a mail]# <strong>service sendmail restart
</strong>Shutting down sm-client:                                   [  OK  ]
Shutting down sendmail:                                    [  OK  ]
Starting sendmail:                                         [  OK  ]
Starting sm-client:                                        [  OK  ]</pre>
<p>ทดลองเชื่อมต่อแบบ SMTP Connection จากเครื่องอื่นอีกครั้ง</p>
<pre>[other1@client1 ~]$ <strong>telnet 192.168.1.1 25
</strong>Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is '^]'.
220 fc12-64a.spalinux.com ESMTP Sendmail 8.14.3/8.14.3; Sun, 29 Nov 2009 14:17:23 +0700
<strong>QUIT</strong>
221 2.0.0 fc12-64a.spalinux.com closing connection
Connection closed by foreign host.</pre>
<p>พิมพ์คำสั่ง QUIT เพื่อออกจากคำสั่ง telnet ของการเชื่อมต่อแบบ SMTP</p>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/11/basic_configure_sendmail/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

