<?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; Email</title>
	<atom:link href="http://spalinux.com/category/email/feed" rel="self" type="application/rss+xml" />
	<link>http://spalinux.com</link>
	<description>Resources for Relaxing Linux System Administrators</description>
	<lastBuildDate>Sat, 21 Jan 2012 16:07:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</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>คอนฟิก 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>
		<item>
		<title>เขียนโปรแกรม PHP เพื่อส่งเมล์ผ่าน gmail</title>
		<link>http://spalinux.com/2008/05/php_sending_email_gmail</link>
		<comments>http://spalinux.com/2008/05/php_sending_email_gmail#comments</comments>
		<pubDate>Wed, 21 May 2008 09:37:30 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Email]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=22</guid>
		<description><![CDATA[ขอแวบมาเขียนบทความเกี่ยวกับการเขียนโปรแกรมซะหน่อย หลังจากเขียนสำหรับผู้ดูแลระบบมาหลายบทความแล้ว บทความนี้ขอกล่าวถึงการเขียนโปรแกรม PHP เพื่อส่งอีเมล์ผ่านบริการ SMTP ของ gmail โดยเราจะอาศัย class library ที่ชื่อ PHPMailer เพื่อให้สามารถใช้ SSL SMTP ของ gmail ได้ ดาวน์โหลดและติดตั้ง PHPMailer เริ่มต้นเราต้องดาวน์โหลด PHPMailer มาติดตั้งก่อน โดยสามารถดูลิ้งค์ดาวน์โหลดได้ที่ ข้อมูลอ้างอิง ด้านล่างของบทความนี้ ไฟล์ที่เราได้มาจากการดาวน์โหลดจะมีหลายไฟล์ ทั้งไฟล์ class ตัวอย่างการใช้งาน เอกสารต่างๆ ไฟล์ที่จำเป็นจริงๆ จะมี 3 ไฟล์คือ class.phpmailer.php class.pop3.php class.smtp.php เขียนโปรแกรมทดสอบการส่งอีเมล์ ด้านล่างจะเป็นตัวอย่างโปรแกรมที่ใช้ส่งอีเมล์ โดยเราต้องแก้ค่าตัวแปรต่างๆ เช่น Username, Password,&#8230; ของ gmail ที่ใช้ &#60;?php require(&#8220;class.phpmailer.php&#8221;); require(&#8220;class.smtp.php&#8221;); $mail=new PHPMailer(); $mail-&#62;IsSMTP(); $mail-&#62;IsHTML(true); [...]]]></description>
			<content:encoded><![CDATA[<p>ขอแวบมาเขียนบทความเกี่ยวกับการเขียนโปรแกรมซะหน่อย หลังจากเขียนสำหรับผู้ดูแลระบบมาหลายบทความแล้ว</p>
<p>บทความนี้ขอกล่าวถึงการเขียนโปรแกรม PHP เพื่อส่งอีเมล์ผ่านบริการ SMTP ของ gmail โดยเราจะอาศัย class library ที่ชื่อ PHPMailer เพื่อให้สามารถใช้ SSL SMTP ของ gmail ได้</p>
<p><span id="more-22"></span></p>
<p><strong>ดาวน์โหลดและติดตั้ง PHPMailer</strong><br />
เริ่มต้นเราต้องดาวน์โหลด PHPMailer มาติดตั้งก่อน โดยสามารถดูลิ้งค์ดาวน์โหลดได้ที่ ข้อมูลอ้างอิง ด้านล่างของบทความนี้</p>
<p>ไฟล์ที่เราได้มาจากการดาวน์โหลดจะมีหลายไฟล์ ทั้งไฟล์ class ตัวอย่างการใช้งาน เอกสารต่างๆ ไฟล์ที่จำเป็นจริงๆ จะมี 3 ไฟล์คือ class.phpmailer.php class.pop3.php class.smtp.php</p>
<p><strong>เขียนโปรแกรมทดสอบการส่งอีเมล์</strong><br />
ด้านล่างจะเป็นตัวอย่างโปรแกรมที่ใช้ส่งอีเมล์ โดยเราต้องแก้ค่าตัวแปรต่างๆ เช่น Username, Password,&#8230; ของ gmail ที่ใช้</p>
<p><code>&lt;?php</code></p>
<p>require(&#8220;class.phpmailer.php&#8221;);<br />
require(&#8220;class.smtp.php&#8221;);</p>
<p>$mail=new PHPMailer();</p>
<p>$mail-&gt;IsSMTP();<br />
$mail-&gt;IsHTML(true);</p>
<p>$mail-&gt;SMTPAuth = true;<br />
$mail-&gt;SMTPSecure = &#8220;ssl&#8221;;<br />
$mail-&gt;Host = &#8220;smtp.gmail.com&#8221;;<br />
$mail-&gt;Port = 465;</p>
<p>$mail-&gt;Username = &#8220;<strong>username@gmail.com</strong>&#8220;;<br />
$mail-&gt;Password = &#8220;<strong>password</strong>&#8220;;</p>
<p>$mail-&gt;From = &#8220;<strong>username@gmail.com</strong>&#8220;;<br />
$mail-&gt;FromName = &#8220;<strong>Sender Name</strong>&#8220;;<br />
$mail-&gt;Subject = &#8220;<strong>This is a testing subject from gmail</strong>&#8220;;<br />
$mail-&gt;Body = &#8220;<strong>Hi,This is testing &lt;b&gt;HTML&lt;/b&gt; message</strong>.&#8221;;</p>
<p>$mail-&gt;AddAddress(&#8220;<strong>your-friend@domain.com</strong>&#8220;,&#8221;<strong>your-friend@domain.com</strong>&#8220;);<br />
if(!$mail-&gt;Send()) {<br />
echo &#8220;Mailer Error: &#8221; . $mail-&gt;ErrorInfo;<br />
} else {<br />
echo &#8220;Message has been sent&#8221;;<br />
}<br />
?&gt;</p>
<p>เมื่อแก้ไขไฟล์เรียบร้อย จะรันผ่านเว็บหรือเป็นแบบคอมมานด์ก็ได้ ลองดูครับ</p>
<p><strong>ข้อมูลอ้างอิง</strong></p>
<ul>
<li><a href="http://phpmailer.codeworxtech.com/" target="_blank">PHPMailer Official Site</a></li>
<li><a href="http://sourceforge.net/project/showfiles.php?group_id=26031" target="_blank">Download PHPMailer</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2008/05/php_sending_email_gmail/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

