您的位置:首页 > 运维架构 > Linux

linux msmtp+mutt 自动发送邮件

2012-04-11 10:22 459 查看
     最近公司有个新的需求,将公司数据库日志内容作为邮件的内容发送出去,然后我同事就使用sendmail的功能配合到shell中,将日志文件发送了出去,但是sendmail设置和使用比较麻烦,且对环境要求比较高。所以就想可否使用一个比较简单的方法,后来查阅得知:msmtp+mutt可以用来以命令行方式发送邮件。照网上的方法就操作了一边,现在将安装方法贴在下面,方便以后查询。
实验环境:redhat5.4 gcc(GCC编译器要求全部安装)
    首先在根下创建temp文件夹,然后将安装包下载到temp文件夹下,接着解压缩该文件。随后进入该文件夹执行编译安装(一定将gcc的所有编译软件全部安装上去),随后创建etc目录,新建msmtprc配置文件。
说明:用yum进入本地安装源,将所有gcc开头的软件全部用yum安装掉,挨踢乐曾经就因为单单只用yum -y install gcc 结果安装msmtp失败,所以请安装不完整的同学一起看看。
配置yum的方法在我的博客文章里也有讲过。
---------------------------------------------------------------------------
以下这段如果gcc安装过了就无视。
[root@localhost /]# cd /mnt/Service
[root@localhost /]# yum -y install gcc*
---------------------------------------------------------------------------
[root@localhost /]# mkdir /temp/
[root@localhost /]# cd /temp/
[root@localhost /]# wget http://nchc.dl.sourceforge.net/sourceforge/msmtp/msmtp-1.4.17.tar.bz2 [root@localhost /]# tar xvf msmtp-1.4.17.tar.bz2
[root@localhost /]# cd msmtp-1.4.17
[root@localhost /]# ./configure --prefix=/usr/local/msmtp
[root@localhost /]# make
[root@localhost /]# make install
[root@localhost /]# mkdir /usr/local/msmtp/etc
[root@localhost /]# cd /usr/local/msmtp/etc
[root@localhost /]# vim msmtprc
---------------------------------------------------------------------------
将以下配置文档追加到msmtprc中。
==================================
account default
host smtp.xxx.com
port 25
from xxx@xxx.com
auth login
tls off
user xxx@xxx.com
password xxx
logfile /var/log/mmlog
==================================
host:输入smtp地址
port:端口号
from:邮件地址
auth:login
tls:off
user:用户名(xxx@xxx.com)
password:密码
logfile:/var/log/mmlog
随后使用该命令测试邮件是否设置好了。
---------------------------------------------------------------------------
[root@localhost /]#/usr/local/msmtp/bin/msmtp xxx@xxx.com
---------------------------------------------------------------------------
随便输入一些内容,然后按Ctrl+D结束编辑,然后查看无错误的话,就去收邮件拉。
随后要安装mutt
---------------------------------------------------------------------------
[root@localhost /]#yum -y install mutt
---------------------------------------------------------------------------
配置muttrc文件
---------------------------------------------------------------------------
[root@localhost /]#vi /etc/Muttrc
---------------------------------------------------------------------------
将以下内容追加到Muttrc下
==================================
set sendmail="/usr/local/msmtp/bin/msmtp"
set use_from=yes
set realname="xxx@xxx.com"
set editor="vim"
==================================
接下来我们可以尝试去使用命令行方式来发送。
---------------------------------------------------------------------------
[root@localhost /]#mutt -s "test" -a /etc/hosts xxx@xxx.com < /etc/passwd
---------------------------------------------------------------------------
-s=邮件名-a=附件内容〈=将文件内容添加到邮件内容中
===========================================================================================
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: