Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1308694
  • 博文数量: 273
  • 博客积分: 5865
  • 博客等级: 准将
  • 技术积分: 3280
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-11 10:01
文章分类

全部博文(273)

文章存档

2015年(33)

2014年(11)

2013年(11)

2012年(136)

2011年(32)

2010年(50)

分类: LINUX

2012-09-06 11:14:43

sendmail中如果非root用户想实现邮件转发功能,可以通过.forward文件来实现,这个文件是放在用户主目录下的

如用户peter的主目录是/home/peter

[peter@station11 ~]$ cat /home/peter/.forward
test
\peter
[peter@station11 ~]$
如果邮件的转发同时要转发给本身一份,则需要在用户名前添加一个\代表取消转发,免得无限循环下去呵!

清空maillog记录

[root@station11 ~]# > /var/log/maillog

发测试邮件
[root@station11 ~]# ls  -l | mail -s "test .forward file function "

检查mail的log信息
[root@station11 ~]# cat /var/log/maillog
Jan  2 14:10:42 station11 sendmail[26665]: o02MAg5a026665: from=root, size=303, class=0, nrcpts=1, msgid=<>,
Jan  2 14:10:42 station11 sendmail[26666]: o02MAgIw026666: from=<>, size=609, class=0, nrcpts=1, msgid=<>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Jan  2 14:10:42 station11 sendmail[26665]: o02MAg5a026665: , ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30303, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (o02MAgIw026666 Message accepted for delivery)
Jan  2 14:10:42 station11 sendmail[26667]: o02MAgIw026666: to=test, ctladdr=<> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=60847, dsn=2.0.0, stat=Sent
Jan  2 14:10:42 station11 sendmail[26667]: o02MAgIw026666: to=\\peter, ctladdr=<> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=60847, dsn=2.0.0, stat=Sent
[root@station11 ~]#

看maillog日志格式:

时间戳++++++++主机名(这里是station11)++++++++服务器软件名++++to=发送给谁++++ctladdr=谁发的邮件stat=Send说明邮件已发送出去,但不保证对端收到呵,但能说明本端服务配置基本是正常的

还有一种方法是查mailq,mailq显示出站邮件队列,如果 报告队列中有消息则说明本地或者远程配置或者网络有问题呵!自己给自己发邮件则说明本地配置有问题了

[root@station11 mqueue]# mailq
/var/spool/mqueue is empty
                Total requests: 0

这时要说明的是一个权限问题,.forward文件只允许属主有写权限,其他不能有写要限

[root@station11 ~]# ls /home/peter/.forward -l
-rwxrwxr-x 1 peter peter 12 Jan  1 15:06 /home/peter/.forward
[root@station11 ~]# > /var/log/maillog
[root@station11 ~]# ls -l | mail -s "test .forward permission " peter
[root@station11 ~]# mailq
/var/spool/mqueue is empty
                Total requests: 0
[root@station11 ~]# su - test
[test@station11 ~]$ mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/test": 2 messages 1 new 2 unread
U  1   Fri Jan  1 15:22  20/722   "test ls command 2"
>N  2   Sat Jan  2 14:10  20/921   "test .forward file function"
& q
Held 2 messages in /var/spool/mail/test
[test@station11 ~]$ su - peter
Password:
[peter@station11 ~]$ mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/peter": 3 messages 2 new 3 unread
U  1   Fri Jan  1 15:06  20/722   "test ls command 1"
>N  2   Sat Jan  2 14:10  20/921   "test .forward file function"
N  3   Sat Jan  2 14:36  20/896   "test .forward permission"
& q
Held 3 messages in /var/spool/mail/peter
[peter@station11 ~]$ exit
logout
[test@station11 ~]$ mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/test": 2 messages 2 unread
>U  1   Fri Jan  1 15:22  20/722   "test ls command 2"
U  2   Sat Jan  2 14:10  21/931   "test .forward file function"
& q
Held 2 messages in /var/spool/mail/test
[test@station11 ~]$ exit
logout
[root@station11 ~]# cat /var/log/maillog
Jan  2 14:36:05 station11 sendmail[27438]: o02Ma5sj027438: from=root, size=278, class=0, nrcpts=1, msgid=<>,
Jan  2 14:36:05 station11 sendmail[27439]: o02Ma5SB027439: from=<>, size=584, class=0, nrcpts=1, msgid=<>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Jan  2 14:36:05 station11 sendmail[27440]: o02Ma5SB027439: forward /home/peter/.forward: Group writable file                         <===test用户收不到邮件的原因在这里
Jan  2 14:36:05 station11 sendmail[27438]: o02Ma5sj027438: to=peter, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30278, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (o02Ma5SB027439 Message accepted for delivery)
Jan  2 14:36:05 station11 sendmail[27440]: o02Ma5SB027439: to=<>, ctladdr=<> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30822, dsn=2.0.0, stat=Sent
[root@station11 ~]#

下面是更新了权限后,test用户很书就收到邮件,注意邮件标题呵!

[root@station11 ~]# chmod 700 /home/peter/.forward
[root@station11 ~]#
[root@station11 ~]#
[root@station11 ~]#
[root@station11 ~]# > /var/log/maillog
[root@station11 ~]# ls -l | mail -s "test .forward permission XXXXXXXXXXXXXX " peter
[root@station11 ~]# su - test
[test@station11 ~]$ mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/test": 3 messages 1 new 3 unread
U  1   Fri Jan  1 15:22  20/722   "test ls command 2"
U  2   Sat Jan  2 14:10  21/931   "test .forward file function"
>N  3   Sat Jan  2 14:38  20/911   "test .forward permission XXXXXXXXXXXXXX"
& q
Held 3 messages in /var/spool/mail/test
[test@station11 ~]$

阅读(2183) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~