IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]ubuntu14.04+mutt+msmtp 配置 linux 下命令行邮件客户端

    qcpm1983发表于 2014-12-11 16:38:12
    love 0


    安装软件 msmtp mutt

    apt-get install -y msmtp mutt
    

    配置 msmtp

    安装完成之后先配置 msmtp,默认的配置文件根据每个操作系统版本不一样,通过msmtp --version 来查看。

    # msmtp --version
    msmtp version 1.4.31
    Platform: x86_64-pc-linux-gnu
    TLS/SSL library: GnuTLS
    Authentication library: GNU SASL
    Supported authentication methods:
    plain scram-sha-1 cram-md5 gssapi external digest-md5 login ntlm
    IDN support: enabled
    NLS: enabled, LOCALEDIR is /usr/share/locale
    Keyring support: none
    System configuration file name: /etc/msmtprc
    User configuration file name: /root/.msmtprc
    
    Copyright (C) 2013 Martin Lambers and others.
    This is free software.  You may redistribute copies of it under the terms of
    the GNU General Public License .
    There is NO WARRANTY, to the extent permitted by law.
    

    我们这里使用 /etc/msmtprc 来设置机器的全局配置,不用管原来的配置文件,用下面的配置文件替换

    # Set default values for all following accounts.
    defaults
    # The SMTP server of the provider.
    account  default
    host smtp.163.com
    from xxx@163.com
    auth login
    user xxx@163.com
    password xxxpassowrd
    tls off
    syslog on
    

    到这里msmtp 就配置好了,更多详细的配置可以使用 man msmtp 来得到帮助,帮助最后还有配置示例。

    配置 mutt

    mutt 的配置文件也有 2 个。

    ~/.muttrc or ~/.mutt/muttrc
        User configuration file.
    
    /etc/Muttrc
        System-wide configuration file.
    

    同样,我们采用全局配置。

    set sendmail="/usr/bin/msmtp" #你的msmtp命令路径
    set use_from=yes
    set realname="xxx@163.com"  #这里设置的是你发件人别名,可以不是邮件地址
    set editor="vim"
    

    测试发送邮件

    df -h |mutt -s "useage of hd" xxx@163.com
    

    使用客户端收取邮件内容如下:

    useage of hd
    xxx@163.com
    发给 xxx
    详细信息2014-12-12 05:28
    Filesystem                   Size  Used Avail Use% Mounted on
    /dev/mapper/ubuntu--vg-root   95G  2.1G   88G   3% /
    none                         4.0K     0  4.0K   0% /sys/fs/cgroup
    udev                         3.9G  4.0K  3.9G   1% /dev
    tmpfs                        799M  552K  798M   1% /run
    none                         5.0M     0  5.0M   0% /run/lock
    none                         3.9G     0  3.9G   0% /run/shm
    none                         100M     0  100M   0% /run/user
    /dev/sda1                    236M   37M  187M  17% /boot
    

    配置 nagios 的报警邮件也使用 mutt 来发送。在 nagios 的 command.cfg 中将mail 命令替换成 mutt

    # 'notify-host-by-email' command definition
    define command{
            command_name    notify-host-by-email
            command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mutt -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
            }
    
    # 'notify-service-by-email' command definition
    define command{
            command_name    notify-service-by-email
            command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mutt -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
            }


沪ICP备19023445号-2号
友情链接