<?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>服务器安全维护工作室 &#187; 使用 Sendmail 架设邮件服务器</title>
	<atom:link href="https://www.fuwuqiok.com/tag/%e4%bd%bf%e7%94%a8-sendmail-%e6%9e%b6%e8%ae%be%e9%82%ae%e4%bb%b6%e6%9c%8d%e5%8a%a1%e5%99%a8/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fuwuqiok.com</link>
	<description></description>
	<lastBuildDate>Sun, 01 Mar 2020 07:28:40 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.26</generator>
	<item>
		<title>使用 Sendmail 架设邮件服务器</title>
		<link>https://www.fuwuqiok.com/%e4%bd%bf%e7%94%a8-sendmail-%e6%9e%b6%e8%ae%be%e9%82%ae%e4%bb%b6%e6%9c%8d%e5%8a%a1%e5%99%a8/</link>
		<comments>https://www.fuwuqiok.com/%e4%bd%bf%e7%94%a8-sendmail-%e6%9e%b6%e8%ae%be%e9%82%ae%e4%bb%b6%e6%9c%8d%e5%8a%a1%e5%99%a8/#comments</comments>
		<pubDate>Tue, 01 Dec 2015 14:36:21 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[服务器迁移]]></category>
		<category><![CDATA[使用 Sendmail 架设邮件服务器]]></category>

		<guid isPermaLink="false">https://www.fuwuqiok.com/?p=2803</guid>
		<description><![CDATA[<p>Sendmail 是一款简单易用的邮件服务软件（邮件传输代理、MTA），许多 Linux 发行版都内置 Sen [&#8230;]</p>
<p><a rel="nofollow" href="https://www.fuwuqiok.com/%e4%bd%bf%e7%94%a8-sendmail-%e6%9e%b6%e8%ae%be%e9%82%ae%e4%bb%b6%e6%9c%8d%e5%8a%a1%e5%99%a8/">使用 Sendmail 架设邮件服务器</a>，首发于<a rel="nofollow" href="https://www.fuwuqiok.com">服务器安全维护工作室</a>。</p>
]]></description>
				<content:encoded><![CDATA[<div class="entry-content">
<p>Sendmail 是一款简单易用的邮件服务软件（邮件传输代理、MTA），许多 Linux 发行版都内置 Sendmail 程序，只需简单设置即可将服务器配置为可收发邮件的服务器，下面以 CentOS 6作为例子。</p>
<p><strong>1、域名的设置</strong><br />
首先需要设置域名 DNS 的 MX 记录和 SPF 记录，一个典型的域名设置如下：</p>
<pre lang="config">记录类型    主机名   目标
------------------------------------
A         @        123.123.123.123 （这里设置为你服务器的IP）
CNAME     www      your-domain.com
CNAME     SMTP     your-domain.com
MX        @        smtp.your-domain.com
TXT       @        v=spf1 a mx ~all</pre>
<p>MX记录是邮件服务器必须依赖的，而TXT（SPF）是用来防止自己的邮件服务器发送的邮件不被当成垃圾邮件（spam email），假如不增加SPF记录的话对方邮箱服务器可能会把你发出的邮件直接丢弃、或者塞到垃圾邮件文件夹里，所以这条记录现今是必不可少的，更多的 SPF设置方法<a href="http://www.openspf.org/">参阅这里</a>。</p>
<p><strong>2、设置 Sendmail</strong></p>
<p>下面使用的 Sendmail 版本是 8.14，设置方法非常简单，首先确保你系统已经有 sendmail 及其相关服务了：</p>
<pre lang="bash"># yum install sendmail
# yum install sendmail-cf
# yum install sendmail-devel
# yum install sendmail-milter</pre>
<p>然后切换到 /etc/mail 目录，<br />
a、编辑 local-host-names 文件，在里面添加你的域名，比如 yourdomain.com，一行一个域名。<br />
b、编辑 sendmail.mc，把下面两行的注释（即 “dnl #”）删除：</p>
<p>TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN’)dnl<br />
define(`confAUTH_MECHANISMS’, `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN’)dnl</p>
<p>c、编辑 sendmail.mc，把下面这行：<br />
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA’)dnl<br />
当中的“127.0.0.1”替换成“0.0.0.0”，以允许外网可以访问你的服务器，假如有多个IP地址，而且只想让其中的某一个用作邮件服务，那么就把具体的IP地址填上去。<br />
d、添加一个本地帐号，比如“webmaster”，并设置密码。<br />
e、编辑 virtusertable 文件，增加这样的一行：<br />
webmaster@yourdomain.com        webmaster<br />
f、重新编译一下 sendmail 的设置：</p>
<pre lang="bash"># m4 sendmail.mc &gt; sendmail.cf
# make</pre>
<p>g、重启 sendmail 服务，这样就设置好了，你已经可以使用 mail 命令发送邮件了。</p>
<p><strong>3、设置 IMAP 或 POP3 服务</strong></p>
<p>虽然经过上面的设置我们已经可以对外发送邮件了（使用命令或编程方式），而且回复的邮件也能接收，不过如果我们提供IMAP或者POP3服务，就能方便各种邮件客户端收发邮件。dovecot 就是这样的一个服务。<br />
a、先安装 dovecot 服务：</p>
<pre lang="bash"># yum install dovecot</pre>
<p>b、编辑dovecot的配置文件，即 /etc/dovecot.conf，有些 Linux 发行版有可能位于 /etc/dovecot/conf.d/，在 #protocols 一行下面增加：<br />
protocols imap, pop3<br />
假如你不需要 pop3，则直接去除。<br />
c、继续编辑dovecot的配置文件，在 #mail_location 下面增加：<br />
mail_location = mbox:~/mail:INBOX=/var/mail/%u</p>
<p>e、由于这样简单配置的IMAP或者POP3的数据传输是没有经过加密的，有些 Linux 发行版会禁止明文密码登录（当然位于服务器的web程序发送邮件不受此限制），所以还需要在 #disable_plaintext_auth 这行下面增加：<br />
disable_plaintext_auth = no<br />
f、重启 dovecot 服务，现在可以使用邮件客户端软件来测试收发邮件了。</p>
<p><strong>4、在 Web App 里发送邮件</strong></p>
<p>这里举一个使用 Java 收发邮件例子。在 Java 里发送邮件一般用 JavaMail，而更简单的是使用 Apache Commons Email 组件：</p>
<pre lang="java">Email email = new SimpleEmail();
email.setHostName("smtp.yourdomain.com");
email.setAuthenticator(new DefaultAuthenticator("webmaster", "password"));
email.setTLS(false);
email.setFrom("webmaster@yourdomain.com");
email.setSubject("Hello");
email.setMsg("This is a test mail");
email.addTo("foo@bar.com");
email.send();</pre>
<p><strong>参考资料：</strong><br />
1、<a href="http://nixcraft.com/mail-servers/14855-centos-sendmail-roundcube-configuration-tutorial.html">CentOS Sendmail Roundcube Configuration Tutorial</a><br />
2、<a href="http://commons.apache.org/email/">Apache Commons Email</a></p>
</div>
<p><a rel="nofollow" href="https://www.fuwuqiok.com/%e4%bd%bf%e7%94%a8-sendmail-%e6%9e%b6%e8%ae%be%e9%82%ae%e4%bb%b6%e6%9c%8d%e5%8a%a1%e5%99%a8/">使用 Sendmail 架设邮件服务器</a>，首发于<a rel="nofollow" href="https://www.fuwuqiok.com">服务器安全维护工作室</a>。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.fuwuqiok.com/%e4%bd%bf%e7%94%a8-sendmail-%e6%9e%b6%e8%ae%be%e9%82%ae%e4%bb%b6%e6%9c%8d%e5%8a%a1%e5%99%a8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
