How to insert new line in the email using linux mail command?
Try using echo -e
echo -e "Hello \n World"
You can type man echo
from the command line to read more.
How to insert new line in message body of email using Bash?
Tested on MacOS with Bash 3.2
mail -s "$subject" MyTestEmail@gmail.com <<< $(printf "%s\r\n%s\n" "Note that $start and $end use server time" "the end")
This is a screen shot from gmail of the email received
mail bash variable on a new line
It seems that Outlook removed extra line breaks from my message. I was able to use awk to fix the problem.
echo "$d" | awk '{ print $0" " }' | mail -s "subject" -r "Name<Name@somewhere.com >" first.last@somewhere.com
This reads every single line, and re-prints it with three spaces at the end. Outlook is now happy.
https://blog.dhampir.no/content/outlook-removes-extra-line-breaks-from-plain-text-emails-how-to-stop-it
Sending mail in bash script outputs literal \n instead of a new line
In bash you should use following syntax
message_txt=$'This is just a test.\n Goodbye!'
Single quotes preceded by a $
is a new syntax that allows to insert escape sequences in strings.
Check following documentation about the quotation mechanism of bash
for ANSI C-like escape sequences
Send mail with newline and Linux mail command via Pythons subprocess
You need to put the body and subject in quotes. It's easier if you use an f-string
cmd = f"echo '{body}' | mail -s '{subject}' -r '{fromAddr}' '{toAddr}'"
Note that you need to ensure that there are no quote characters in any of the parameters -- make sure you don't allow single quote in the password.
How to insert a new line in Linux shell script?
The simplest way to insert a new line between echo
statements is to insert an echo
without arguments, for example:
echo Create the snapshots
echo
echo Snapshot created
That is, echo
without any arguments will print a blank line.
Another alternative to use a single echo
statement with the -e
flag and embedded newline characters \n
:
echo -e "Create the snapshots\n\nSnapshot created"
However, this is not portable, as the -e
flag doesn't work consistently in all systems. A better way if you really want to do this is using printf
:
printf "Create the snapshots\n\nSnapshot created\n"
This works more reliably in many systems, though it's not POSIX compliant. Notice that you must manually add a \n
at the end, as printf
doesn't append a newline automatically as echo
does.
fail to add new line to email body for sendmail -t | Unix |
This approach worked for me
Writing the Body text content within html tags
#Pre-Defined parameters
EmailSubjectDemo="New Message : `date`"
EmailbodyDemo="<html> <body> Hi Bro How <br> are <br> you </body> </html>"
EmailToDemo="abc@xyz.com,pqr@f.com"
EmailFromDemo="abc@yz.com,pqr@f.com"
#Sending mail
(
echo "From : $EmailFromDemo"
echo "To : $EmailToDemo"
echo "MIME-Version: 1.0"
echo "Subject: $EmailSubjectDemo"
echo "Content-Type: text\html"
echo -e "$EmailbodyDemo"
) sendmail -t
Related Topics
Where Is Hardware Timer Interrupt
Merge PDF Files with Numerical Sort
Sort Across Multiple Files in Linux
Download Images from Google with Command Line
Not Authorized for Query on Admin.System.Namespaces on Mongodb
@Reboot Is Not Working in Cron
How to Get Started Writing a Compositing Wm
How to Find or Calculate a Linux Process's Page Table Size and Other Kernel Accounting
How to Setup Oracle Odbc Drivers on Rhel 6/Linux
The Return Code from 'Grep' Is Not as Expected on Linux
Error: Ld.So: Object Ld_Preload Cannot Be Preloaded: Ignored
How to Delete the First Column ( Which Is in Fact Row Names) from a Data File in Linux
Register Variables in Loop in an Ansible Playbook
What Does It Mean to Say "Linux Kernel Is Preemptive"