linux用mail往qq邮箱发邮件

因为qq邮箱的一些安全设置,本机用mail命令投递的邮件

smtp服务器用的是localhost的sendmail或者postfix

所以邮件的from是来自localhost.localdomain邮件

qq一律拒之!

并且返回550错误


此处配置mail命令使用远程的qq的SMTP服务器发送邮件,并用qq邮箱登录

1.配置发送环境

# cat /etc/mail.rc |grep -v -E "^#|^$"
set hold
set append
set ask
set crt
set dot
set keep
set emptybox
set indentprefix="> "
set quote
set sendcharsets=iso-8859-1,utf-8
set showname
set showto
set newmail=nopoll
set autocollapse
ignore received in-reply-to message-id references
ignore mime-version content-transfer-encoding
fwdretain subject date from to
set bsdcompat
set from=994414615\@qq.com  smtp=smtp.exmail.qq.com           //邮件来自
set smtp-auth-user=994414615\@qq.com smtp-auth-password=YOUPASSWORD smtp-auth=login       //登录qq SMTP服务器的用户名和密码
*********************************************************************

注意:上配置文件中的from项和user项中的qq不可取消,不然shell

会将@当特殊符处理!

*********************************************************************

2.发送命令

# echo "a test mail to qq mail server\!\!"|mail -s caiwenguang [email protected]

可以用qq邮箱接收报警邮件,这样如果qq在线的话可以有邮件可以随时提示!


昨完测试之后,打算将此应用到服务器上,结果maillog中抛出错误

Mar 31 14:43:26 web-server01 sendmail[30245]: s2V6hP11030245: to=EOT,[email protected], ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=60079, relay=[127.0.0.1] [127.0.0.1], dsn=4.0.0, stat=Deferred: Connection refused by [127.0.0.1]
Mar 31 14:46:32 web-server01 sendmail[30255]: s2V6kWZt030255: from=root, size=77, class=0, nrcpts=1, msgid=<[email protected]>, relay=root@localhost


抑郁了!!!


几经波折发现RHEL5.4上的mail命令和sendmail有这千丝万缕的联系

索性卸了sendmail和mailx8.1安装新的mailx包

yum remove sendmail


安装新的mailx包

# wget http://clang.googlecode.com/files/mailx-12.4.tar.bz2

# make

# make install UCBINSTALL=/usr/bin/install


test -d /usr/local/bin || mkdir -p /usr/local/bin
/usr/bin/install -c mailx /usr/local/bin/mailx
strip /usr/local/bin/mailx                                              //此命令
test -d /usr/local/share/man/man1 || mkdir -p /usr/local/share/man/man1
/usr/bin/install -c -m 644 mailx.1 /usr/local/share/man/man1/mailx.1
test -d /etc || mkdir -p /etc
test -f /etc/nail.rc || \
        /usr/bin/install -c -m 644 nail.rc /etc/nail.rc                  //这个配置文件

查看修改后的配置文件

# cat /etc/nail.rc |grep -vE "^#|^$"
set hold
set append
set ask
set crt
set dot
set keep
set emptybox
set indentprefix="> "
set quote
set sendcharsets=iso-8859-1,utf-8
set showname
set showto
set newmail=nopoll
set autocollapse
ignore received in-reply-to message-id references
ignore mime-version content-transfer-encoding
fwdretain subject date from to
set bsdcompat
set from=994414615\@qq.com  smtp=smtp.exmail.qq.com
set smtp-auth-user=994414615\@qq.com smtp-auth-password=YOUPASSWORD smtp-auth=login

再测试

# echo "this is a test mail,hello cai\!"| /usr/local/bin/mailx  -s testmail [email protected]


成功发送!!!


############################################

迷途小运维随笔

作者:john

转载请注明出处

你可能感兴趣的:(随笔)