通过命令行发送外部邮件

2016年5月6日

7:44

最近公司这边需要每日发送报表,自带的sendmail不会用,就到网上找了下利用smtp的协议发送邮件的命令行客户端,最后找到mutt和msmtp结合使用可以达到目的,所以记录下使用过程和配置过程。

安装mutt和msmtp。yum之 。

  1. 配置msmtp

    1. 查看配置文件和msmtp相关信息:可以看到系统配置文件为/etc/msmtprc,用户的配置文件为/root/.mstprc


      [[email protected] ~]# 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.

    1. vim /root/.msmtprc

配置如下的内容:


[email protected] ~]# 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 [email protected]       

auth login

#这里auth要指定方式,如果用ON的话,会报错。我这里直接使用login的方式

user [email protected]

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 [email protected]

 

 

 

# Set a default account

account default : report

 

  1. 紧接着通过echo xxx | msmtp [email protected]就可以就可以收到邮件了,不过很怪异的是,邮件发送人,正文都为空,不知道什么原因。搜索了半天,没有找到原因。因为后续准备使用mutt发送邮件,所以也没管他,后续继续配置 mutt
  1. 配置mutt:

set editor="vim"

set realname="[email protected]"

set sendmail="/usr/bin/msmtp"

set use_from=yes

  1. 测试mutt是否可以 echo xxx | mutt -s "主题"  [email protected] 即可查看是否接收到,这里可以看到主题和发送人。
时间: 2024-08-27 22:02:50

通过命令行发送外部邮件的相关文章

利用命令行引用外部jar包以使程序正常运行的4种方法

声明:本博客为原创博客,未经允许,不得转载!原文链接为http://blog.csdn.net/bettarwang/article/details/30976069 平时写一些小的Java Demo时我比较喜欢用UltraEdit或记事本写完后,直接利用命令行进行编译和运行.这样的好处就是方便快捷.相信有这个习惯的人应该还大有人在.但是如果要引用外部jar包,应该如何操作呢?在写JDBC的一些Demo时,由于要利用jar包来加载相应的数据库,每个Demo都用到了外部jar包,所以特地总结了一下

利用命令行引用外部jar包以使程序正常执行的4种方法

声明:本博客为原创博客.未经同意.不得转载!原文链接为http://blog.csdn.net/bettarwang/article/details/30976069 平时写一些小的Java Demo时我比較喜欢用UltraEdit或记事本写完后,直接利用命令行进行编译和执行.这种优点就是方便快捷.相信有这个习惯的人应该还大有人在. 可是假设要引用外部jar包.应该怎样操作呢?在写JDBC的一些Demo时.因为要利用jar包来载入对应的数据库.每一个Demo都用到了外部jar包,所以特地总结了一

关于Cad中向命令行发送命令的提醒

由于种种原因需要向CAD的Editor发送命令,此时应特别注意: 能用代码解决的问题绝不用sendcommand的方式,因为不知道什么时候就出了什么鸟问题,向命令行发送命令其不可控因素太多了: 能用异步的就用异步吧,因为经过近段时间的测试发现异步反而不容易出问题,所谓异步即:SendStringToExecute; 同步的也可以用,不过不可以用在与用户的交互过程中,比如命令行还在执行过程中发送命令去做别的事情,这样就会出莫名的线程错误:

如何在Linux下发送外部邮件

Linux自带mail命令的测试 步骤1: 通过mail命令发送邮件,发现无法发到外网邮箱,从网上找到相关说明,查看mail和mailx的版本 [[email protected] ~]# rpm -qa|grep mailxmailx-8.1.1-44.2.2 必须要 12以上的版本才可以向外部发邮件.(参考) 步骤2: 下载mailx-12.4并安装.下载地址:参考. 解压:tar -jxvf mailx-12.4.tar.gz2 安装:make; 可以参照这个流程进行,该流程已经验证可行.

命令行发送UDP

https://www.cnblogs.com/Dennis-mi/articles/6866762.html: 如果往本地UDP端口發送數據,那麼可以使用以下命令:echo “hello” > /dev/udp/192.168.1.81/5060 意思是往本地192.168.1.81的5060端口發送數據包hello. 如果往遠程UDP端口發送數據,那麼可以使用以下命令:echo “hello” | socat - udp4-datagram:192.168.1.80:5060 意思是往遠程1

飞秋命令行

飞秋命令行发送消息和文件接口: 一.增加通过命令行发送信息.图片.文件接口(feiq.exe(指定飞秋所在的路径) \msg:*.xml)二.增加通过命令行导出好友列表接口(feiq.exe \userxml:*.xml)三.增加通过命令行导出在线发送联系人好友列表接口(feiq.exe \contactxml:*.xml)四.增加通过命令行发表新日志接口(feiq.exe \newzone:*.html)      注:(1)以上命令行参数中的文件路径是相对于飞秋工作目录下ParamFile文

在Linux命令行下发送html格式的邮件

在Linux利用formail+sendmail来发送带图片的邮件 formail接收html格式的文件作为邮件的内容,这样就可以解决发送带图片邮件的问题了,因为html中可以插入图片,只要给出的img src为可用的链接就行了. 命令格式如下cat mailfile.html | formail -I "MIME-Version:1.0" -I "Content-type:text/html;charset=gb2312" -I "Subject:lay

在命令行上 Ubuntu 下使用 mutt 和 msmtp 发送 Gmail 邮件

在命令行写email from ubuntu 参考:      http://www.habadog.com/2011/11/23/send-mail-with-msmtp-mutt-linux      http://www.absolutelytech.com/2010/07/17/howto-configure-msmtp-to-work-with-gmail-on-linux msmtp 是一款专门负责邮件发送的客户端软件,基于GPL发布,支持TLS/SSL.DNS模式.IPv6.服务器

邮件开发(二)命令行发邮件

1.打开命令行,输入指令:telnet smtp.qq.com 587 这儿的服务器地址和端口是上面提到的,但是465端口似乎用不了,这儿使用587端口. 2.回车后出现以下界面: 3.向服务器表明身份: 1.输入:ehlo zby 2.回显250状态码 3.zby可以任意替换,这儿是我姓名简写. 4.输入命令:starttls 5.输入:auth login 6.看到334返回码,开始邮箱验证,输入邮箱的base64编码(运行之前的工具类得到): 7.看到334返回码,开始授权码验证,是授权码