文档来源:http://blog.chinaunix.net/u/23251/showart_2093914.html
linux mail利用外部邮箱地址发邮件
bin/mail会默认使用本地sendmail发送邮件,这样要求本地的机器必须安装和启动Sendmail
服务,配置非常麻烦,而且会带来不必要的
资源占用。而通过修改配置文件可以使用外部SMTP服务器,可以达到不使用sendmail而用外
部的smtp服务器发送邮件的目的:
修改/etc/nail.rc (/etc/mail.rc)
也可自定义一个xxx.rc,通过环境变量指定
set from=fromUser@domain.com smtp=smtp.domain.comset smtp-auth-user=username
smtp-auth-password=passwordset smtp-auth=login
说明:
from是发送的邮件地址
smtp是发生的外部smtp邮件服务器的地址
smtp-auth-user是外部smtp邮件服务器认证的用户名
smtp-auth-password是外部smtp邮件服务器认证的用户密码
smtp-auth是邮件认证的方式
配置成功后,就可以使用了
可以发送一封邮件测试一下:
mail -s "test" -a attachmentuser@sohu.com, xxx@163.com
一个示例:
#mail.rc
set from=fromUser@domain.com smtp=smtp.domain.comset smtp-auth-user=username
smtp-auth-password=passwordset smtp-auth=login
#sendmail_report.sh
#/bin/sh
export MAILRC=~/bin/bob.rc
cd ~/report/db
today=`date +"%Y%m%d"`
rm *.tar.gz >/dev/null 2>&1
tar -czvf db_$today.tar.gz *$today.* > mailfile.txt
mail -s "*$today.rep" toUser@domain.com toUser_22@domain.com -a db_$today.tar.gz
< mailfile.txt
这样就可发送文件了.
通过邮件,就可以把巡检报告打包发到邮箱.回家也可以掌握数据库的情况了.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10248702/viewspace-626951/ ,如需转载,请注明出处,否则将追究法律责任。