send mail from linux terminal in one line [closed] send mail from linux terminal in one line [closed] linux linux

send mail from linux terminal in one line [closed]


mail can represent quite a couple of programs on a linux system. What you want behind it is either sendmail or postfix. I recommend the latter.

You can install it via your favorite package manager. Then you have to configure it, and once you have done that, you can send email like this:

 echo "My message" | mail -s subject user@gmail.com

See the manual for more information.

As far as configuring postfix goes, there's plenty of articles on the internet on how to do it.Unless you're on a public server with a registered domain, you generally want to forward the email to a SMTP server that you can send email from.

For gmail, for example, followhttp://rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp/or any other similar tutorial.


You can use an echo with a pipe to avoid prompts or confirmation.

echo "This is the body" | mail -s "This is the subject" user@gmail.com


echo "Subject: test" | /usr/sbin/sendmail user@domain.com

This enables you to do it within one command line without having to echo a text file. This answer builds on top of @mti2935's answer. So credit goes there.