What is the best way to append a new line to a message and then send that per mail?
message=""
for f in $backupdir/*; do
message ="..."
done
echo "$message" | mailx -a 'Content-Type: text/html' -s "[Test]" email
i found message ="message"$'\n'
but this has some bugs when opening that mail in outlook
i tried mailx with html tag but this does not append a new line at all.
CodePudding user response:
using html you can put the <br />
tag in the message.
CodePudding user response:
i found message ="message"$'\n' but this has some bugs when opening that mail in outlook
The reason for this is because you asks mailx to encode the mail into HTML.
if you need an HTML email, then you need to compose HTML paragraphs
message="${message}<p>Some new paragraph.</p>"
# ...
printf %s "$message" | mailx -a 'Content-Type: text/html' -s '[Test]' [email protected]
Now if you want to send plain text messages, regular newlines are just fine:
message="${message}Some new paragraph.
"
# Or Bash's c-style string to add the newline and concatenate string
message =$'Another paragraph\n'
printf %s "$message" | mailx -a 'Content-Type: text/plain' -s '[Test]' [email protected]