Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send mail from linux terminal in one line [closed]

Tags:

linux

email

People also ask

Can I send email from Linux command line?

sendmail Command Sendmail is one of the most popular SMTP servers in Linux. You can easily send emails directly from the command line using the sendmail command. To route the information, the sendmail command makes use of the network configured on your system.

How do you end a mail command in Linux?

To quit the mail editor without sending the message, use the ~q subcommand or the interrupt key sequence (usually the Alt-Pause or Ctrl-C key sequence). The mail program must be installed on your system.

How do you send mail in Linux?

Use the clause of mail to end the mail, the type “-s” to specify the subject, type the recipient email address, press the ENTER key, it will ask for the CC (carbon copy) give it or skip it by pressing the ENTER key, type the message, you want to communicate and finally press CTRL+D to send the message.

How do I send an attachment as the body of an email in Linux?

Use the new attachment switch (-a) in mailx to send attachments with the mail. The -a options is easier to use that the uuencode command. The above command will print a new blank line. Type the body of the message here and press [ctrl] + [d] to send.


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

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, follow http://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" [email protected]

echo "Subject: test" | /usr/sbin/sendmail [email protected]

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.


You can also use sendmail:

/usr/sbin/sendmail [email protected] < /file/to/send