LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 11111|回复: 34

安装 Exim 邮件服务器

[复制链接]
发表于 2003-7-15 14:01:48 | 显示全部楼层 |阅读模式
安装 Exim 邮件服务器

前提条件:具有Internet连接,有正确的DNS的MX记录指向你的smtp服务器

Debian Linux 缺省安装的邮件传输服务软件为 exim 3.35 。下面为 exim 的设置过程:


一、基本配置

==============================================================================
You must choose one of the options below:

(1) Internet site; mail is sent and received directly using SMTP. If your
     needs don't fit neatly into any category, you probably want to start
     with this one and then edit the config file by hand.

(2) Internet site using smarthost: You receive Internet mail on this
     machine, either directly by SMTP or by running a utility such as
     fetchmail. Outgoing mail is sent using a smarthost. optionally with
     addresses rewritten. This is probably what you want for a dialup
     system.

(3) Satellite system: All mail is sent to another machine, called a "smart
     host" for delivery. root and postmaster mail is delivered according
     to /etc/aliases. No mail is received locally.

(4) Local delivery only: You are not on a network.  Mail for local users
     is delivered.

(5) No configuration: No configuration will be done now; your mail system
     will be broken and should not be used. You must then do the
     configuration yourself later or run this script, /usr/sbin/eximconfig,
     as root. Look in /usr/share/doc/exim/example.conf.gz

Select a number from 1 to 5, from the list above.
Enter value (default=`1', `x' to restart):1

这里选择1,使这台机器作为一台互联网上的标准SMTP邮件传输服务器。


==============================================================================
What is the `visible' mail name of your system? This will appear on
From: lines of outgoing messages.
Enter value (default=`smtp.foo.com', `x' to restart):

这里我们确认邮件域的名称,缺省系统使用主机的名称;可以根据实际情况设置。


==============================================================================
Does this system have any other names which may appear on incoming
mail messages, apart from the visible name above (smtp.foo.com) and
localhost?

By default all domains will be treated the same; if you want different
domain names to be treated differently, you will need to edit the config
file afterwards: see the documentation for the "domains" director
option.

If there are any more, enter them here, separated with spaces or commas.
If there are none, say `none'.
Enter value (default=`none', `x' to restart):foo.com

这里我们来设置除了缺省的邮件域,还可以接受什么邮件域,作为本地邮件域。注意,这里需要与本地DNS的
MX记录相配合。


==============================================================================
All mail from here or specified other local machines to anywhere on
the internet will be accepted, as will mail from anywhere on the
internet to here.

Are there any domains you want to relay mail for---that is, you are
prepared to accept mail for them from anywhere on the internet, but
they are not local domains.

If there are any, enter them here, separated with spaces or commas. You
can use wildcards. If there are none, say `none'. If you want to relay
mail for all domains that specify you as an MX, then say `mx'
Enter value (default=`none', `x' to restart):

我们可以指定转发域,也可通过MX 记录指定转发域,这样将不会要求认证。

==============================================================================
Obviously, any machines that use us as a smarthost have to be excluded
from the relaying controls, as using us to relay mail for them is the
whole point.

Are there any networks of local machines you want to relay mail for?

If there are any, enter them here, separated with spaces or commas. You
should use the standard address/length format (e.g. 194.222.242.0/24)
If there are none, say `none'.

You need to double the colons in IPv6 addreses (e.g. 5f03::1200::836f::::/48)
Enter value (default=`none', `x' to restart):

我们在后面要设置通过认证来转发邮件,所以我们这里使用缺省值none。

==============================================================================
Mail for the `postmaster' and `root' accounts is usually redirected
to one or more user accounts, of the actual system administrators.
By default, I'll set things up so that mail for `postmaster' and for
various system accounts is redirected to `root', and mail for `root'
is redirected to a real user.  This can be changed by editing /etc/aliases.

Note that postmaster-mail should usually be read on the system it is
directed to, rather than being forwarded elsewhere, so (at least one of)
the users you choose should not redirect their mail off this machine.

Which user account(s) should system administrator mail go to ?
Enter one or more usernames separated by spaces or commas .  Enter
`none' if you want to leave this mail in `root's mailbox - NB this
is strongly discouraged.  Also, note that usernames should be lowercase!
Enter value (`x' to restart):eagle

这里我们将系统的缺省用户的信件转给一个实际的管理员邮件账户。


The following configuration has been entered:

==============================================================================
Mail generated on this system will have `smtp.foo.com' used
as the domain part (after the @) in the From: field and similar places.

The following domain(s) will be recognised as referring to this system:
localhost, smtp.foo.com, foo.com

Mail for postmaster, root, etc. will be sent to eagle.

Local mail is delivered.

Outbound remote mail is looked up in the Internet DNS, and delivered
using that data if any is found; otherwise such messages are bounced.


Note that you can set email addresses used for outgoing mail by editing
/etc/email-addresses.

Is this OK ?  Hit Return or type `y' to confirm it and install,
or `n' to make changes (in which case we'll go round again, giving you
your previous answers as defaults.     (Y/n)

这里系统提示配置结果,接受上述设置。

Keeping previous /etc/exim/exim.conf as /etc/exim/exim.conf.O

Keeping previous /etc/aliases as /etc/aliases.O

Keeping previous /etc/mailname as /etc/mailname.O

Configuration installed.

系统将保存相关配置文件。

二、微调

这里我们对一些常用功能进行配置和补充,使其成为一个可以实际工作的邮件服务器。

1.增加转发域
relay_domains = *.foo.com
# 接受从外部进入的、目的域为foo.com的邮件转发。否则邮件无法进入。

2.检查邮件头,判断用户是否存在
sender_verify = true
# If this option is true, envelope sender addresses on incoming SMTP messages are checked to ensure that they are valid.

3.限制邮箱的大小
在 TRANSPORTS CONFIGURATION 的 local_delivery 加入:
  maildir_tag = ,S=$message_size
  quota = ${lookup{$local_part}lsearch*{/etc/exim/quota}{$value}{0M}}
  quota_size_regex = S=(\d+)$
  quota_warn_threshold = 85%
  quota_warn_message = "\
    To: $local_part@$domain\n\
    Subject: Your mailbox full\n\n\
    This message is automatically created \
    by mail delivery software.\n\n\
    The size of your mailbox has exceeded \
    a warning threshold that is\n\
    set by the system administrator.\n"
# 对本地邮箱大小进行限制,限额来自文件quota
quota文件内容的格式如下:
username           10M

4.限制传输邮件的大小
在 TRANSPORTS CONFIGURATION 的需要限制的transports加入:
message_size_limit = 5M

5.开启SMTP认证的方式:PLAIN 和 LOGIN
将 AUTHENTICATION CONFIGURATION 章节里的 plain 和 login 相关部分的注释号去掉;
产生passwd 文件,passwd 文件内容的格式如下:
username : passwd
username和passwd 来源于/etc/passwd和/etc/shadow
可以通过下面的脚本产生:
#!/bin/sh

awk -F: '
/^(sash)?root:/ { next }
/^[^:]*:.[^:]/ { print $1 ":" $2 }
' /etc/shadow > /etc/exim/auth.passwd.tmp

mv /etc/exim/auth.passwd.tmp /etc/exim/passwd
chown mail:mail /etc/exim/passwd
chmod 0400 /etc/exim/passwd

write by Eagle Xu  2003-07-15
欢迎指正。email: f_eagle@163.com
发表于 2003-7-15 17:32:40 | 显示全部楼层

咳咳,提问

MX记录是什么?我拨号上网dns是动态分配的怎么配合?
 楼主| 发表于 2003-7-15 19:20:26 | 显示全部楼层

回复: 咳咳,提问

最初由 fatoo 发表
MX记录是什么?我拨号上网dns是动态分配的怎么配合?


拨号上网啊,建议你用sylpheed收发信件,这里介绍的是MTA
发表于 2003-7-19 02:42:09 | 显示全部楼层

回复: 咳咳,提问

最初由 fatoo 发表
我拨号上网dns是动态分配的怎么配合?


动态ip的话,可以用 exim4, 现在 exim4 里已经新增这个选项了。
我用下来效果不错。
 楼主| 发表于 2003-7-24 12:17:31 | 显示全部楼层

Exim 中两个有用的设置,请斑竹合并到 “安装 Exim 邮件服务器”

# This specifies the name of the current host. This is used in the HELO
#  command for outgoing SMTP messages, and as the default for qualify_domain.

primary_hostname = mail.foo.com

在缺省的情况下,你会发现由你的邮件服务器发出的邮件的头信息 Received: 里的主机名称是你的当前主机的名称(是不是有点 ;-P),也许这并不是你想要的。你的主机名可能是 cs.foo.com ,这看起来像是个CS服务器而不是个mail服务器。这时你可以通过上面的设置使你发出邮件的头信息里的 Received: 显示你想要的主机名,比如 mail.foo.com ,这样看起来是不是正式一点。当然你的 DNS 应该能 CNAME 这个主机名,我就是这样做的。


# This sets the timeout on RFC 1413 identification calls. If it is set to zero,
# no RFC 1413 calls are ever made.

rfc1413_query_timeout = 0s

在缺省的情况下,邮件服务器会进行 RFC1413 identification 这个工作,如果此时对方的主机对此不予响应,将会有一定的延时;当你通过在 windows 里的 MUA 发送信件时会感到这个延时。通过上面的设置可以关闭 RFC1413 identification 。
发表于 2004-6-9 22:51:46 | 显示全部楼层

回复: 回复: 咳咳,提问

最初由 Xiaojun 发表
动态ip的话,可以用 exim4, 现在 exim4 里已经新增这个选项了。
我用下来效果不错。


能详细的说说看吗?我也是拨号上网的哦。
发表于 2004-6-22 01:15:28 | 显示全部楼层
按这个帖子,倒可以发去。但收到的信并不能回复。呵呵。不知道是什么原因。那位如果是adls+动态dns的话,可以给出过程。偶搞到现在还没有搞定。

另外,我还找到一个不错的帖子。
http://newbiedoc.sourceforge.net ... /index-exim.html.en
感兴趣者可以看看。但我详细看了这个帖子,对于我并不成功:-)
发表于 2004-6-22 04:18:05 | 显示全部楼层
我就是adls+动态dns,完全可以回复,主要就是要把邮件域或者本地邮件域设置为你的动态域名, 目的是接受从外部进入的、目的域为你的域名的邮件转发(其实就是别人回复给你的邮件)。否则邮件无法进入。

给出我的exim.conf:

# This is the main exim configuration file.
# It was originally generated by `eximconfig', part of the exim package
# distributed with Debian, but it may edited by the mail system administrator.
# This file originally generated by eximconfig at ÈÕ  2ÔÂ 29 21:12:34 CST 2004
# See exim info section for details of the things that can be configured here.

# Please see the manual for a complete list
# of all the runtime configuration options that can be included in a
# configuration file.

# This file is divided into several parts, all but the last of which are
# terminated by a line containing the word "end". The parts must appear
# in the correct order, and all must be present (even if some of them are
# in fact empty). Blank lines, and lines starting with # are ignored.

######################################################################
#                    MAIN CONFIGURATION SETTINGS                     #
######################################################################

# Specify the domain you want to be added to all unqualified addresses
# here. Unqualified addresses are accepted only from local callers by
# default. See the receiver_unqualified_{hosts,nets} options if you want
# to permit unqualified addresses from remote sources. If this option is
# not set, the primary_hostname value is used for qualification.

qualify_domain = guccio

# If you want unqualified recipient addresses to be qualified with a different
# domain to unqualified sender addresses, specify the recipient domain here.
# If this option is not set, the qualify_domain value is used.

# qualify_recipient =

# Specify your local domains as a colon-separated list here. If this option
# is not set (i.e. not mentioned in the configuration file), the
# qualify_recipient value is used as the only local domain. If you do not want
# to do any local deliveries, uncomment the following line, but do not supply
# any data for it. This sets local_domains to an empty string, which is not
# the same as not mentioning it at all. An empty string specifies that there
# are no local domains; not setting it at all causes the default value (the
# setting of qualify_recipient) to be used.

local_domains = localhost:guccio:guccio.3322.org

# Allow mail addressed to our hostname, or to our IP address.

local_domains_include_host = true
local_domains_include_host_literals = true

# Domains we relay for; that is domains that aren't considered local but we
# accept mail for them.

#relay_domains =

# If this is uncommented, we accept and relay mail for all domains we are
# in the DNS as an MX for.

#relay_domains_include_local_mx = true

# No local deliveries will ever be run under the uids of these users (a colon-
# separated list). An attempt to do so gets changed so that it runs under the
# uid of "nobody" instead. This is a paranoic safety catch. Note the default
# setting means you cannot deliver mail addressed to root as if it were a
# normal user. This isn't usually a problem, as most sites have an alias for
# root that redirects such mail to a human administrator.

# However, you chose not to have such an alias, so this is commented out

#never_users = root

# The setting below causes Exim to do a reverse DNS lookup on all incoming
# IP calls, in order to get the true host name. If you feel this is too
# expensive, you can specify the networks for which a lookup is done, or
# remove the setting entirely.

host_lookup = *

# The setting below would, if uncommented, cause Exim to check the syntax of
# all the headers that are supposed to contain email addresses (To:, From:,
# etc). This reduces the level of bounced bounces considerably.

# headers_check_syntax

# Exim contains support for the Realtime Blocking List (RBL), and the many
# similar services that are being maintained as part of the DNS. See
# http://www.mail-abuse.org/ for background. The line below, if uncommented,
# will reject mail from hosts in the RBL, and add warning headers to mail
# from hosts in a list of dynamic-IP dialups. Note that MAPS may charge
# for this service.

#rbl_domains = rbl.mail-abuse.org/reject : dialups.mail-abuse.org/warn

# http://www.rfc-ignorant.org is another interesting site with a number of
# services you can use with the rbl_domains option

# The setting below allows your host to be used as a mail relay only by
# localhost: it locks out the use of your host as a mail relay by any
# other host. See the section of the manual entitled "Control of relaying"
# for more info.

host_accept_relay = 127.0.0.1 : ::::1

# This setting allows anyone who has authenticated to use your host as a
# mail relay. To use this you will need to set up some authenticators at
# the end of the file

host_auth_accept_relay = *

# If you want Exim to support the "percent hack" for all your local domains,
# uncomment the following line. This is the feature by which mail addressed
# to x%y@z (where z is one of your local domains) is locally rerouted to
# x@y and sent on. Otherwise x%y is treated as an ordinary local part

# percent_hack_domains=*

# If this option is set, then any process that is running as one of the
# listed users may pass a message to Exim and specify the sender's
# address using the "-f" command line option, without Exim's adding a
# "Sender" header.

trusted_users = mail:uucp

# If this option is true, the SMTP command VRFY is supported on incoming
# SMTP connections; otherwise it is not.

smtp_verify = true

# Some operating systems use the "gecos" field in the system password file
# to hold other information in addition to users' real names. Exim looks up
# this field when it is creating "sender" and "from" headers. If these options
# are set, exim uses "gecos_pattern" to parse the gecos field, and then
# expands "gecos_name" as the user's name. $1 etc refer to sub-fields matched
# by the pattern.

gecos_pattern = ^([^,:]*)
gecos_name = $1

# This sets the maximum number of messages that will be accepted in one
# connection and immediately delivered. If one connection sends more
# messages than this, any further ones are accepted and queued but not
# delivered. The default is 10, which is probably enough for most purposes,
# but is too low on dialup SMTP systems, which often have many more mails
# queued for them when they connect.

smtp_accept_queue_per_connection = 100

# Send a mail to the postmaster when a message is frozen. There are many
# reasons this could happen; one is if exim cannot deliver a mail with no
# return address (normally a bounce) another that may be common on dialup
# systems is if a DNS lookup of a smarthost fails. Read the documentation
# for more details: you might like to look at the auto_thaw option

freeze_tell_mailmaster = true

# This string defines the contents of the \`Received' message header that
# is added to each message, except for the timestamp, which is automatically
# added on at the end, preceded by a semicolon. The string is expanded each
# time it is used.

received_header_text = "Received: \
         ${if def:sender_rcvhost {from ${sender_rcvhost}\n\t}\
         {${if def:sender_ident {from ${sender_ident} }}\
         ${if def:sender_helo_name {(helo=${sender_helo_name})\n\t}}}}\
         by ${primary_hostname} \
         ${if def:received_protocol {with ${received_protocol}}} \
         (Exim ${version_number} #${compile_number} (Debian))\n\t\
         id ${message_id}\
         ${if def:received_for {\n\tfor <$received_for>}}"

# Attempt to verify recipient address before receiving mail, so that mails
# to invalid addresses are rejected rather than accepted and then bounced.
# Apparently some spammers are abusing servers that accept and then bounce
# to send bounces containing their spam to people.

receiver_try_verify = true

# This would make exim advertise the 8BIT-MIME option. According to
# RFC1652, this means it will take an 8bit message, and ensure it gets
# delivered correctly. exim won't do this: it is entirely 8bit clean
# but won't do any conversion if the next hop isn't. Therefore, if you
# set this option you are asking exim to lie and not be RFC
# compliant. But some people want it.

#accept_8bitmime = true

# This will cause it to accept mail only from the local interface

#local_interfaces = 127.0.0.1

# If this next line is uncommented, any user can see the mail queue
# by using the mailq command or exim -bp.

#queue_list_requires_admin = false

# The errors_copy line will cause the specified address to receive a copy
# of bounces generated on the system.

#errors_copy = *@* postmaster@yourdomain

#
end
发表于 2004-6-22 08:30:39 | 显示全部楼层
ok已经解决。把动态域名设为本地邮件便可。等再遇到问题再提出:-)
发表于 2004-6-22 19:10:03 | 显示全部楼层
hello。遇到一个问题。当exim接受到外面来的邮件时。比如我的情况:
有两个用用户:faint root,当他们都有新的邮件时。但此时root还没有收信,但用户faint却login系统,系统提示有新邮件。偶发现:
$cat /var/mail/faint 可以看到root的邮件内容呀。
$ls /var/mail/faint -l
total 0
-rw-rw----    1 faint       mail            0 Jun 23 02:29 faint
这样相当危险哦。请请exim按受邮件后存放的位置是什么,权限又是什么?(呵呵,我都不知道修改了那里了)!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表