Generate html mail in bash to use with mail

toddehb

New Member
Joined
Oct 24, 2023
Messages
1
Reaction score
0
Credits
14
Hi,

I created a simple script in which a certain information is send via mail like this:

Code:
printf "Dear $i, please enable 2fa on $site.\n\n Your inital code: \n $code \n\n\n For detailed instructions visit:\n https://docs.nextcloud.com/server/latest/user_manual/en/user_2fa.html \n\n You must complete the above steps from instructions, otherwise you will not be able to log into your account a second time!\n\n Regards - Your Site Administrator from $site" | mail -s "Urgent notice from $site" $email -r $mail_from

I would rather send this mail as html with predefined variables. Tried to create a simple html file, saved it locally an read it in the script via cat:

Code:
template=`cat ./mail_template`

Contents of mail_template is:

Code:
<!DOCTYPE html>
<body>

Dear $i,

please enable 2fa on $site. This is very important to protect your identity.

Your inital code for logging in to your account the next time: 

$code

For detailed instructions please visit:
https://docs.nextcloud.com/server/latest/user_manual/en/user_2fa.html

You must complete the above steps from instructions, otherwise you will not be able to log into your account a second time!

In short you need to do the following steps:

1.) Log in to your account on $site using above code
2.) Enable 2FA as shown in the instruction ( link above )
3.) Enable security tokens as shown in instructions ( link above )

<bold>Attention!!!</bold>
Don't save security tokens to your Nextcloud File Storage. Put them in another safe( preferably encrypted ) place, or print them out and store them in a vault.


Regards - Your Site Administrator from $site


</body>
</html>

Then the new mail statement is this:

Code:
 printf "$template" | mail -a 'Content-Type: text/html'  -s "Urgent notice from $site" $email -r $mail_from

Unfortunately this is not working. The variables from the mail_template are written as normal strings, also the html tags are not recognized.

Any any how to do this the correct way? Thanks.

cheers, toddehb
 

Members online


Top