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 multiple ways to send emails from the Linux command line. This is useful for sending email through our shell scripts, cronjobs 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.
Created a file with email content:
cat /tmp/email.txt Subject: Terminal Email Send Email Content line 1 Email Content line 2
Now send email using the following command.
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.
mail -s "Test Subject" user@example.com < /dev/null
-s is used for defining subject for email.
Also, you can send an attachment with this command. Use -a for mailx and -A for mailutils.
mail -a /opt/backup.sql -s "Backup File" user@example.com < /dev/null
- Here
-a is used for attachments. Use -A for debian based systems, which uses mailutils package.
You may face issue: Bash: mail: command not found
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 emails from Linux terminal from local user mailboxes, also useful to read emails from POP/IMAP servers. Mutt command is little similar to mail command. Use few of below examples to send an email.
mutt -s "Test Email" user@example.com < /dev/null
Send an email including an 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 per my experience, all system administrators use telnet command to test remote port connectivity test or login to the server remotely. Most of the newbie in Linux doesn't know that we can send email using telnet also, which is the better way to troubleshoot email sending problems. Below is an example of email sending.
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 -0400HELO yahoo.com 250 tecadmin.net Hello tecadmin.net [127.0.0.1], pleased to meet youmail from: sender@tecadmin.net 250 2.1.0 sender@tecadmin.net... Sender okrcpt to: myemail@ymail.com 250 2.1.5 myemail@ymail.com... Recipient okdata 354 Enter mail, end with "." on a line by itselfHey This is test email only Thanks . 250 2.0.0 r9M95xgc014513 Message accepted for deliveryquit 221 2.0.0 fbreveal.com closing connection Connection closed by foreign host. ::...
免责声明:
当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
内容版权归原作者所有;
本人对内容的有效性/合法性不承担任何强制性责任.
若有不妥, 欢迎评注提醒:
或是邮件反馈可也:
askdama[AT]googlegroups.com
点击注册~> 获得 100$ 体验券:![]()
订阅 substack 体验古早写作:
关注公众号, 持续获得相关各种嗯哼:
![]()
自怼圈/年度番新
![]()
关于 ~ DebugUself with DAMA ;-)
粤ICP备18025058号-1
公安备案号: 44049002000656 ...::