sending email as html messes up formatting

aristosv

New Member
Joined
Mar 13, 2022
Messages
2
Reaction score
0
Credits
20
This script goes through a google calendar, picks up any events that contain phone numbers starting with 95, 96, 97, 99 and emails a report to $emailaddress.

Bash:
#!/bin/bash
# emails $emailaddress a list of client appointments for the $currentdate
# sources $emailaddress and $currentdate from operations/variables
# sources $clientname from $clientdir/config

#variables
parentdir=$(dirname "$(dirname "$(readlink -f -- "$0")")")
source "$parentdir/operations/variables"

get_events () {
echo "Reminders Daily Report for $currentdate"
echo
for clientdir in $(ls $parentdir/clients -F | grep \/$ | sed 's#/$##') ; do
 source "$parentdir/clients/$clientdir/config"
 echo "$clientname Reminders $currentdate"
 gcalcli --config-folder $parentdir/clients/$clientdir/auth agenda --tsv \
 "$(date -d 'now')" "$(date -d 'now + 24 hours')" \
 | grep -e 95 -e 96 -e 97 -e 99 \
 | awk '{$1=$3=$4=""; print $0}'
 echo
done
}

send_mail () {
mail -a 'Content-Type: text/html' -s "Reminders Daily Report" $emailaddress
}

"get_events" | send_mail

My problem is that the report arrives in the email, in a single line, like this:

Code:
Reminders Daily Report for 13/03/2022 Client1 Reminders 13/03/2022 21:00 991234567 21:30 991234567 Client2 Reminders 13/03/2022 21:00 991234567 21:30 991234567

and I want it to arrive in the email, like this:

Code:
Reminders Daily Report for 13/03/2022

Client1 Reminders 13/03/2022
21:00   991234567
21:30   991234567

Client2 Reminders 13/03/2022
21:00   991234567
21:30   991234567

The problem is resolved when I change "Content-Type: text/html" to "Content-Type: text/plain", but I have to send this as html because I'm planning on adding some html code in the script.

How can I fix this?
Thanks
 


OP
A

aristosv

New Member
Joined
Mar 13, 2022
Messages
2
Reaction score
0
Credits
20
Sorry, I don’t understand what you mean. What can I do to receive the email in the format I mentioned?
 

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
6,154
Reaction score
5,524
Credits
49,608
I'm not completely positive, but I'm pretty sure you'd need the actual html for it to be an html email. You can learn to write html in a day, In your case, you'd want to pay attention to learn tables - like table rows <tr>foo</tr>.

Without the html part of it, you're just sending plain text.
 

X104825

Member
Joined
Feb 23, 2022
Messages
63
Reaction score
9
Credits
396
It would probably be easier to use a third party service like gmail.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Staff online

Members online


Top