可能服务器群已有专用邮件服务器不想在每台服务器上开启sendmail服务,
可以使用此方法让其它WEB服务器等调用,方便管理与维护.
1.首先需要一个SMTP邮件服务器
假设已有一台mail.c1gstudio.com邮件服务器
2.在本机的/etc/mail.rc 尾部输入
set [email protected]
set smtp=mail.c1gstudio.com
set smtp-auth=login
set smtp-auth-user=mailuser
set smtp-auth-password=mailpassword
3.发送邮件
mail -v -s “Hello ” [email protected] < /etc/hosts
收件人可以是多个人以","分割
-v是显示过程
Resolving host mail.c1gstudio.com . . . done.
Connecting to 208.133.200.99 . . . connected.
220 Welcome to mail.c1gstudio.com ESMTP,Warning: Version not Available!
>>> EHLO localhost
250-mta.mail.c1gstudio.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
>>> AUTH LOGIN
334 xcvxcv
>>> xc3xvsd==
334 f32fsdfwq
>>> faddasdfaA==
235 2.0.0 Authentication successful
>>> MAIL FROM:
250 2.1.0 Ok
>>> RCPT TO:
250 2.1.5 Ok
>>> DATA
354 End data with
>>> .
250 2.0.0 Ok: queued as A2E541C41D
>>> QUIT
221 2.0.0 Bye
参考:
http://kc1985.blog.51cto.com/2407758/537881
====================
2012-4-10更新
以上测试是在centos6.0下运行没有问题,但在centos5.x上无法成功,为此放狗搜了半天无果
某天总算发现了差异,原来centos6上是Heirloom Mailx,在debian上用的多,yum search下没有.
centos5.8
mailx -V
8.1 6/6/93. Type ? for help.
“/var/spool/mail/root”: 2 messages 2 new
centos6.0
mailx -V
12.4 7/29/08
找到问题就好办了
heirloom项目网址
http://sourceforge.net/projects/heirloom/
目前最近版是mailx-12.4
1.安装mailx
wget http://sourceforge.net/settings/mirror_choices?projectname=heirloom&filename=heirloom-mailx/12.4/mailx-12.4.tar.bz2
tar jxvf mailx-12.4.tar.bz2
cd mailx-12.4
make
make install
出错
test -d /usr/local/bin || mkdir -p /usr/local/bin
/usr/ucb/install -c mailx /usr/local/bin/mailx
make: /usr/ucb/install: Command not found
make: *** [install] Error 127
make install UCBINSTALL=/usr/bin/install
默认安装在
/usr/local/bin/mailx
/etc/nail.rc
也可以自定义安装目录
make PREFIX=/opt/mailx SYSCONFDIR=/opt/mailx/etc
2.在本机的/etc/nail.rc 尾部输入
注意是nail.rc不是mail.rc
set [email protected]
set smtp=mail.c1gstudio.com
set smtp-auth=login
set smtp-auth-user=mailuser
set smtp-auth-password=mailpassword
3.切换到新mailx
mv /bin/mail /bin/mail.OFF
ln -s /usr/local/bin/mailx /bin/mail
4.测试
mail -v -s “new mailx ” [email protected] < /etc/hosts
Resolving host mail.c1gstudio.com . . . done.
….
==========================
2013-4-26更新
如出错找不到libiconv.so.2
mailx: error while loading shared libraries: libiconv.so.2: cannot open shar
可以查找下libiconv有无安装,再把lib目录放入/etc/ld.so.conf中
一般在/usr/local/lib/
echo ‘/usr/local/lib/’ >> /etc/ld.so.conf
ldconfig -v
No Responses (yet)
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.