标签:
通过命令行发送外部邮件
2016年5月6日
7:44
最近公司这边需要每日发送报表,自带的sendmail不会用,就到网上找了下利用smtp的协议发送邮件的命令行客户端,最后找到mutt和msmtp结合使用可以达到目的,所以记录下使用过程和配置过程。
安装mutt和msmtp。yum之 。
查看配置文件和msmtp相关信息:可以看到系统配置文件为/etc/msmtprc,用户的配置文件为/root/.mstprc | [root@ha1 ~]# msmtp --version msmtp version 1.4.32 Platform: x86_64-redhat-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: Gnome System configuration file name: /etc/msmtprc User configuration file name: /root/.msmtprc
Copyright (C) 2014 Martin Lambers and others. This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law. |
配置如下的内容: | root@ha1 ~]# cat .msmtprc # Example for a user configuration file ~/.msmtprc # # This file focusses on TLS and authentication. Features not used here include # logging, timeouts, SOCKS proxies, TLS parameters, Delivery Status Notification # (DSN) settings, and more.
# Set default values for all following accounts. defaults
logfile /root/msmtp.log # Use the mail submission port 587 instead of the SMTP port 25. #port 587
# Always use TLS. #tls on
# Set a list of trusted CAs for TLS. You can use a system-wide default file, # as in this example, or download the root certificate of your CA and use that. #tls_trust_file /etc/ssl/certs/ca-certificates.crt
# Additionally, you should use the tls_crl_file command to check for revoked # certificates, but unfortunately getting revocation lists and keeping them # up to date is not straightforward. #tls_crl_file ~/.tls-crls
# A freemail service account report
# Host name of the SMTP server
# As an alternative to tls_trust_file/tls_crl_file, you can use tls_fingerprint # to pin a single certificate. You have to update the fingerprint when the # server certificate changes, but an attacker cannot trick you into accepting # a fraudulent certificate. Get the fingerprint with # $ msmtp --serverinfo --tls --tls-certcheck=off --host=smtp.freemail.example #tls_fingerprint 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33
# Envelope-from address
# Authentication. The password is given using one of five methods, see below. host smtp.5ikuma.com domain 5ikuma.com from report@5ikuma.com auth login #这里auth要指定方式,如果用ON的话,会报错。我这里直接使用login的方式 user report@5ikuma.com password *******
# Password method 1: Add the password to the system keyring, and let msmtp get # it automatically. To set the keyring password using Gnome‘s libsecret: # $ secret-tool store --label=msmtp \ # host smtp.freemail.example \ # service smtp \ # user joe.smith
# Password method 2: Store the password in an encrypted file, and tell msmtp # which command to use to decrypt it. This is usually used with GnuPG, as in # this example. Usually gpg-agent will ask once for the decryption password. #passwordeval gpg2 --no-tty -q -d ~/.msmtp-password.gpg
# Password method 3: Store the password directly in this file. Usually it is not # a good idea to store passwords in plain text files. If you do it anyway, at # least make sure that this file can only be read by yourself.
# Password method 4: Store the password in ~/.netrc. This method is probably not # relevant anymore.
# Password method 5: Do not specify a password. Msmtp will then prompt you for # it. This means you need to be able to type into a terminal when msmtp runs.
# A second mail address at the same freemail service #account freemail2 : freemail #from joey@freemail.example
# Set a default account account default : report
|
set editor="vim"
set realname="report@5ikuma.com"
set sendmail="/usr/bin/msmtp"
set use_from=yes
标签:
原文地址:http://www.cnblogs.com/LKad/p/5482609.html