Ubuntu14.04 + mutt + msmtp configure the command line mail client in linux
Install software msmtp mutt
apt-get install -y msmtp mutt
Configure msmtp
After the installation is complete, configure msmtp first. The default configuration file varies with the operating system version and can be viewed through msmtp -- version.
# msmtp --versionmsmtp version 1.4.31Platform: x86_64-pc-linux-gnuTLS/SSL library: GnuTLSAuthentication library: GNU SASLSupported authentication methods:plain scram-sha-1 cram-md5 gssapi external digest-md5 login ntlmIDN support: enabledNLS: enabled, LOCALEDIR is /usr/share/localeKeyring support: noneSystem configuration file name: /etc/msmtprcUser configuration file name: /root/.msmtprcCopyright (C) 2013 Martin Lambers and others.This is free software. You may redistribute copies of it under the terms ofthe GNU General Public License
Here we use/etc/msmtprc to set the global configuration of the machine, regardless of the original configuration file, replace it with the following configuration file
# Set default values for all following accounts.defaults# The SMTP server of the provider.account defaulthost smtp.163.comfrom xxx@163.comauth loginuser xxx@163.compassword xxxpassowrdtls offsyslog on
Msmtp is configured here. For more detailed configuration, you can use man msmtp for help. Finally, there are configuration examples.
Configure mutt
There are also two mutt configuration files.
~/.muttrc or ~/.mutt/muttrc User configuration file./etc/Muttrc System-wide configuration file.
Similarly, we use global configuration.
Set sendmail = "/usr/bin/msmtp" # Your msmtp command path set use_from = yesset realname = "xxx@163.com" # Here you set your sender alias, it may not be the email address set editor = "vim"
Test email sending
df -h |mutt -s "useage of hd" xxx@163.com
Use the client to receive the following email content:
Useage of hdxxx@163.com to xxx detailed information 05: 28 Filesystem Size Used Avail Use % Mounted on/dev/mapper/ubuntu -- vg-root 95G 2.1G 88G 3%/none 4.0 K 0 4.0 K 0%/sys/fs/cgroupudev 3.9G 4.0 K 3.9G 1%/devtmpfs 799 M 552 K 798 M 1%/runnone 5.0 M 0 5.0 M 0%/run/locknone 3.9G 0 3.9G 0%/run/shmnone 100 M 0 100 M 0%/run/user/dev/sda1 236 M 37 M 187 M 17%/boot
Configure the nagios alarm email to be sent using mutt. Replace the mail command with mutt in nagios command. cfg.
# 'notify-host-by-email' command definitiondefine 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 definitiondefine 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$ }