LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using /bin/mail command with a string for message, not a filename? (https://www.linuxquestions.org/questions/linux-newbie-8/using-bin-mail-command-with-a-string-for-message-not-a-filename-630699/)

SirTristan 03-26-2008 02:27 AM

Using /bin/mail command with a string for message, not a filename?
 
I know you can send an email with the contents from a file, e.g.:
Code:

mail -s "The subject" "to@email.com" < /home/message.txt
But how can one specify a message directly, without having to store the message in a file name?

Nathanael 03-26-2008 04:16 AM

i am assuming something linke

Code:

mail -s "subject" "recipient@example.org" <<zzzMAILzzz
hello
this is my message text
with line breaks and everything :-)

enjoy
~me
zzzMAILzzz


SirTristan 03-26-2008 02:52 PM

So start with double less than instead of single, specify a delimiter, enter the message line by line, and then specify the same delimiter again on a line by itself to end the message? That worked, thanks.

Is there any way to do this on one line?

gilead 03-26-2008 05:53 PM

Yes, this will send the echoed message via mail:
Code:

echo "A test message" | mail -s "Test subject" someone@somewhere.com

tsg 03-26-2008 08:22 PM

You can also do
Code:

mail -s "Test Subject" someone@somewhere.com <<<"This is the message."
Check the bash man pages for "here documents" and "here strings".


All times are GMT -5. The time now is 04:04 AM.