<?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>Resources for Relaxing Linux System Administrators</description>
	<lastBuildDate>Mon, 26 Jul 2010 09:51:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<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>
