Sendmail配置说明
1. 如果是独立的邮件服务器,只用正确设置 myhostname 就好,其它的默认配置就ok. myhostname一定要设置可以DNS能正确解析到你的主机IP的域名,这个很重要,不然大部分的邮件服务器都会把你的发送当垃圾邮件拒绝。
# /etc/mail/sendmail.mc
LOCAL_DOMAIN(`localhost.localdomain’)dnl #你的主机域名
2. 如果你的数据中心不允许直接的SMTP发送,那一定会提供relayhost。
# /etc/mail/sendmail.mc
define(`SMART_HOST’, `smtp.bbn.cn’)dnl #主机机提供的relayhost
3. 如果一些目标主机(包括relayhost)接收需要SMTP认证
# /etc/mail/sendmail.mc
AuthInfo:smtp.bbn.cn “U:userid” “P:password” “M:PLAIN” #配置需要认证的目标服务器及用户名密码
4. 如果你的目标主机不是标准的STMP端口(25), 就需要transport的设置
# /etc/mail/sendmail.mc
#SMART_HOST port
define(`SMART_HOST’,`relay:your.relay.system.com’)dnl
define(`RELAY_MAILER’,`esmtp’)dnl
define(`RELAY_MAILER_ARGS’, `TCP $h 587′)dnl
——————–
build sendmail with SASL
# mkdir /etc/mail/auth
# chmod 700 /etc/mail/auth
Add AuthInfo:your.isp.net “U:root” “I:user” “P:password”
to /etc/mail/auth/client-info
makemap hash client-info < client-info
# chmod 600 client-info*
add the following to the sendmail.mc file:
define(`RELAY_MAILER_ARGS', `TCP $h 465')
define(`ESMTP_MAILER_ARGS', `TCP $h 465')
define(`SMART_HOST',`your.isp.net')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5
LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
-----------------------------------------
/etc/mail/sendmail.mc
Mesmtp2525: P=[IPC], F=mDFMuXa, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990, T=DNS/RFC822/SMTP, A=TCP $h 2525
And later on use the mailertable:
domain.invalid esmtp2525:[127.0.0.1]
----------------------------
How do I send using an alternate port?
The port used for outgoing SMTP connections can be changed via the respective *_MAILER_ARGS macros for the various SMTP mailers. In a default configuration, sendmail uses either the relay mailer (for e.g. SMART_HOST when no mailer is specified) or the esmtp mailer (when sending directly to the MX of the recipient domain).
So, if you want all outgoing SMTP connections to use port 2525, you can use this in your .mc file:
define(`RELAY_MAILER_ARGS', `TCP $h 2525') define(`ESMTP_MAILER_ARGS', `TCP $h 2525')
If you want to use an alternate port only for specific destinations, change (e.g.) only the RELAY_MAILER_ARGS, and make sure the relay mailer is not used for anything else. E.g. you can have sendmail use port 2525 only when sending to your domain with this in your .mc file:
FEATURE(`mailertable') define(`confRELAY_MAILER', `esmtp') define(`RELAY_MAILER_ARGS', `TCP $h 2525')
and then in your mailertable:
yourdomain.com relay:mail.yourdomain.com
This will force sendmail to use port 2525 for connections to yourdomain.com. Of course, change 2525 to whatever alternate port number you wish to use.
=====================
Sendmail.mc
=============
.....
FEATURE(nouucp)
FEATURE(mailertable,`text /etc/mailertable')
FEATURE(`relay_hosts_only')
define(`SMART_HOST', mailrelay.mydom.com)
MAILER_DEFINITIONS
MAILER(smtp)
Mesmtp2525, P=[IPC], F=mDFMuXa, S=11/31, R=21, E=\r\n, L=990,
T=DNS/RFC822/SMTP,
A=IPC $h 2525
Mesmtp2526, P=[IPC], F=mDFMuXa, S=11/31, R=21, E=\r\n, L=990,
T=DNS/RFC822/SMTP,
A=IPC $h 2526
Mesmtp2527, P=[IPC], F=mDFMuXa, S=11/31, R=21, E=\r\n, L=990,
T=DNS/RFC822/SMTP,
A=IPC $h 2527
Mesmtp2528, P=[IPC], F=mDFMuXa, S=11/31, R=21, E=\r\n, L=990,
T=DNS/RFC822/SMTP,
A=IPC $h 2528
LOCAL_RULE_0
R$+<@2525.mydom.com.> $#esmtp2525 $@ 2525.mydom.com $:
$1<@2525.mydom.com.>
R$+<@2526.mydom.com.> $#esmtp2526 $@ 2526.mydom.com $:
$1<@2526.mydom.com.>
R$+<@2527.mydom.com.> $#esmtp2527 $@ 2527.mydom.com $:
$1<@2527.mydom.com.>
R$+<@2528.mydom.com.> $#esmtp2528 $@ 2528.mydom.com $:
$1<@2528.mydom.com.>
=====================================
注
restart/reload sendmail
m4 sendmail.mc >sendmail.cf
==================================
Configure sendmail for SMTP relay with your ISP
Author: Sven Knispel
Updated: 05-01-2005
Feedback welcome: linux@cri.ch
Free service provided by: www.cri.ch
The following article explains the setup of sendmail for forwarding mails to your ISP’s smtp server.
It is assumed that you have sendmail up-to-date and configured properly.
Note: this setup does not work properly for smtp-server using SASL (e.g. like smtp.pobox.com)
Most of the commands must be executed with the corresponding rights (using sudo).
1. configure your smtp-server
(this requires that you have the package sendmail-cf installed)
1.1. changes to /etc/mail/sendmail.mc
Uncomment the definition SMART_HOST and add the correspondign FEATURE to it:
define(`SMART_HOST’, `your-smtp-server’)
FEATURE(authinfo)dnl Note: Please note, that these are “oriented” quotes.
1.2. create the new sendmail.cf
Stop sendmail by issuing the command /sbin/service sendmail stop and log on as root to issue this command. m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
1.3. Define the account information for connecting to the smtp-server
Edit/create /etc/mail/authinfo and add the following line:
AuthInfo:
Note:The M: may vary depending on the capabilities of the smtp-server (e.g. CRAM-MD5, PLAIN).
Create authinfo.db:
makemap hash /etc/mail/authinfo < /etc/mail/authinfo
and finally restart sendmail:
/sbin/service sendmail restart
1.4. Configure header rewriting (optional)
Header rewriting consists in replacing the From: and Reply to: in the header of an outgoing mail in order for the recipient to reply to a valid address.
This can be set by editing the file /etc/mail/userdb:
E.g.:
# /etc/mail/userdb
sven:mailname sven@foo.org
Finally create the corresponding database:
makemap btree /etc/mail/userdb.db < /etc/mail/userdb
... and finally restart sendmail:
/sbin/service sendmail restart
1.5. Test your settings
Issue following commands and check the trace for verifying the delivery path:
/usr/sbin/sendmail -bv root@localhost Should show a "local" delivery.
/usr/sbin/sendmail -bv
For troubleshooting you should check the mail-log: /var/log/maillog
2. Forwarding
Forward can be defined in ~/.forward. (just enter the e-mail addressto forward to). Note:The permissions of that file must be adjusted correspondingly in order to avoid sendmail ignoring it (see /var/log/maillog in case of problems).
3. References
For further information I recommend to check following link:
http://www.pl-berichte.de/work/server/mailserver.html
http://www.sendmail.org/~ca/email/auth.html
相关文章:

sendmail 报错:cannot open `/usr/share/sendmail-cf/m4 (2010-08-03 16:25)
分类: 邮件服务
在修改sendmail配置文件 /etc/mail/sendmail.mc 后,使用以下命令生成sendmail.cf文件的时候报错:
m4 sendmail.mc > sendmail.cf
报错内容为:
sendmail.mc:10: m4: cannot open `/usr/share/sendmail-cf/m4/cf.m4′: No such file or directory
解决方法:出现这个报错是因为没有安装sendmail-cf这个软件,yum install sendmail-cf 安装完sendmail-cf后解决问题。