how to insert new line in the email using linux mail command?
echo "Hi xxx, would you tell me something?\\n thanks!\\n -xxx" | mail -s "subject" xxx@gmail.com
The email shows the literal '\n', not a newline, how do fix it?
how to insert new line in the email using linux mail command?
echo "Hi xxx, would you tell me something?\\n thanks!\\n -xxx" | mail -s "subject" xxx@gmail.com
The email shows the literal '\n', not a newline, how do fix it?
Try using echo -e
echo -e "Hello \n World"
You can type man echo
from the command line to read more.
With mailx, if you send the email to oultook user, you can add 2 spaces at the begenig of each line.
{ echo "Hi xxx, would you tell me something" ; echo "thanks!" ; echo "-xxx" } | sed 's/^/ /g' | mailx -s "subject" xxx@domain.com
I encountered this issue and resolved it by surrounding with quotes the variable I was piping into mailx
.
I started with a list of processes from ps i.e. list="$(ps |grep some_process)"
.
Then when I tried to mail that out as follows, the newlines were obliterated:
echo $body | mailx -s "${subject}" recipient@someplace.com
But, simply wrapping $body
with quotes preserved the newlines:
echo "$body" | mailx -s "${subject}" recipient@someplace.com
The accepted answer did not work for me when using the mail command, I had to use
\r
My whole command is
mail -s "SUBJECT" -aFrom:"from@sdf.com "to@sdfd.com" <<< $( echo -e "Line1\rLine2")