5 Ways to Send Email From Linux Command Line
https://tecadmin.net/ways-to-send-email-from-linux-command-line/
We all know the importance of emails these days for information transfer. There are many free emails service providers which we used for use like Gmail, Yahoo, RediffMail etc, which provides a web interface for sending and receiving emails. But this is not enough, sometimes we also required to send emails from system command line. This tutorial will provide you the ways to send emails from Linux command line. This is useful for sending email through our shell scripts, cron jobs etc.

There are various ways to send emails from the command line but here I am sharing few options used by most users. You can use anyone option given below to send email from Linux command line.
1. Using ‘sendmail’ Command
Sendmail is a most popular SMTP server used in most of Linux/Unix distribution. Sendmail allows sending email from command line. Use below instructions to send email using ‘sendmail‘ command.
Create a file using following content.
[root@tecadmin ~]# cat /tmp/email.txt Subject: Terminal Email Send Email Content line 1
Email Content line 2
Subject: line will be used as subject for email.
Now send email using the following command.
[root@tecadmin ~]# sendmail user@example.com < /tmp/email.txt
Read more: Install and Configure Sendmail on CentOS/RHEL
2. Using ‘mail’ Command
mail command is most popular command to send emails from Linux terminal. Use few of below examples to send an email.
[root@tecadmin ~]# mail -s "Test Subject" user@example.com < /dev/null
-s is used for defining subject for email.
Also, you can send the email with an attachment.
# mail -a /opt/backup.sql -s "Backup File" user@example.com < /dev/null
You may face issue: Bash: mail: command not found
-a is used for attachments
Also, we can add comma separated emails to send the email to multiple recipients together.
# mail -s "Test Email" user@example.com,user2@example.com < /dev/null
3. Using 'mutt' command
Mutt is basically used for reading mails from Linux terminal from local user mail boxes, also useful to read emails from POP/IMAP servers. Mutt command is little similar to mail command. Use few of below examples to send email.
# mutt -s "Test Email" user@example.com < /dev/null
Send email including attachment
# mutt -s "Test Email" -a /opt/backup.sql user@example.com < /dev/null
4. Using 'SSMTP' Command
sSMTP allows users to send emails from SMTP server from Linux command line. For example to send an email to user admin@example.com use following command. Now type your subject of the email as below with keyword Subject. After that type your message to be sent to the user, After finishing your message press CTRL+d (^d) to send the email.
# ssmtp admin@example.com
Subject: Test SSMTP Email
Email send test using SSMTP
via SMTP server.
^d
Read more: How to Setup SSMTP Server on Linux
5. Using 'telnet' Command
As my experience all system administrators use telnet command to test remote port connectivity test or login to server remotely. Most of newbie in Linux doesn't know that we can send email using telnet also, which is better way to trouble shoot email sending problems. Below is an example of email sending.
Red marked text is the user input and remaining is the responses of that commands.
# telnet localhost smtp Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 fbreveal.com ESMTP Sendmail 8.13.8/8.13.8; Tue, 22 Oct 2013 05:05:59 -0400
HELO yahoo.com
250 tecadmin.net Hello tecadmin.net [127.0.0.1], pleased to meet you
mail from: sender@tecadmin.net
250 2.1.0 sender@tecadmin.net... Sender ok
rcpt to: myemail@ymail.com
250 2.1.5 myemail@ymail.com... Recipient ok
data
354 Enter mail, end with "." on a line by itself
Hey
This is test email only Thanks
.
250 2.0.0 r9M95xgc014513 Message accepted for delivery
quit
221 2.0.0 fbreveal.com closing connection
Connection closed by foreign host.
Thank you for using this article. We will add more ways soon with this list. We also request you to help me with more commands which you know and not listed above.
http://blog.csdn.net/ithomer/article/details/6776067
linux shell 发送email 邮件
sendmail -s 'Test mail' toywei@dingtalk.com < mail.m
5 Ways to Send Email From Linux Command Line的更多相关文章
- 10 Interesting Linux Command Line Tricks and Tips Worth Knowing
I passionately enjoy working with commands as they offer more control over a Linux system than GUIs( ...
- Linux Command Line Basics
Most of this note comes from the Beginning the Linux Command Line, Second Edition by Sander van Vugt ...
- 15 Examples To Master Linux Command Line History
When you are using Linux command line frequently, using the history effectively can be a major produ ...
- [笔记]The Linux command line
Notes on The Linux Command Line (by W. E. Shotts Jr.) edited by Gopher 感觉博客园是不是搞了什么CSS在里头--在博客园显示效果挺 ...
- 《The Linux Command Line》 读书笔记04 Linux用户以及权限相关命令
Linux用户以及权限相关命令 查看身份 id:Display user identity. 这个命令的输出会显示uid,gid和用户所属的组. uid即user ID,这是账户创建时被赋予的. gi ...
- 《The Linux Command Line》 读书笔记02 关于命令的命令
<The Linux Command Line> 读书笔记02 关于命令的命令 命令的四种类型 type type—Indicate how a command name is inter ...
- 《The Linux Command Line》 读书笔记01 基本命令介绍
<The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...
- Linux Command Line 解析
Linux Command Line 解析 0 处理模型 Linux kernel的启动包括很多组件的初始化和相关配置,这些配置参数一般是通过command line进行配置的.在进行后续分析之前,先 ...
- Reso | The Linux Command Line 的中文版
http://book.haoduoshipin.com/tlcl/book/zh/ 本书是 The Linux Command Line 的中文版, 为大家提供了多种不同的阅读方式. 中英文双语版- ...
随机推荐
- 标准C程序设计七---62
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- Day 16 之二 省市县三级联动
摘录自:雨神,供参考! province_dic = { "河北": { "石家庄": ["鹿泉", "藁城", &qu ...
- 基于现有图像数据创建自定义像素格式的 BufferedImage
在最近的一个项目中,需要实现 Mac OS X 环境下的摄像头图像实时捕获并转换为 Java 中的 BufferedImage 对象.首先通过开发一个本地库实现 Mac OS X 的摄像头图像捕获,采 ...
- javascript --- 多重继承
多重继承就是指,一个子对象中有不止一个父对象的继承模式. 想要实现她,还是非常简单的,而我们只需要延续属性拷贝的继承思路依次扩展对象即可,而对参数中所继承的对象没有限制. function multi ...
- 【maven】架包下载失败,maven引入架包失败,pom文件未报错,但是引用的注解找不到
出现这种问题 看到这个jar包显示是unkown,不知道版本,所以这样的解决方法就是 1.先查看maven设置是使用的自定义的仓库还是默认的仓库 2.删除掉你引用的jar包下载失败的文件夹 3.然后重 ...
- IDG | 四则运算表达式计算
分析 首先将中缀表达式转换为后缀表达式(逆波兰式),然后使用栈进行计算. 没有考虑括号.小数. 代码 import java.util.LinkedList; import java.util.Lis ...
- 从头写一个Cucumber测试(二) Cucumber Test
转载:https://yaowenjie.github.io/%E7%BC%96%E7%A8%8B%E7%9B%B8%E5%85%B3/cucumber-test-part-2 承接上文 前一篇博 ...
- 简单理解 ES7 Decorator(装饰器)
如何使用ES7 Decorator给你的游戏人物开挂? // 预告: 本文有点小难度,对js不太熟的人可能比较懵逼 // 本文的目的是让你们知其然 // ======================= ...
- best-time-to-buy-and-sell-stock系列——先买入后卖出股票的最大值
1. Say you have an array for which the i th element is the price of a given stock on day i . If you ...
- nagios插件之登陆SBC监控电话数
运行:sbc_calls_status_new auto_ssh_sbc_10_17.sh | auto_ssh_sbc_11_17.sh vi sbc_calls_status_new.c #inc ...