Hi guys I was creating a email OTP template using doPost function in Google scripts. Actually I have an application in which when user ask for OTP then his details like name,email and app generated OTP are sent to this script. Then it sends the email to the user. But I thought to implement a beautiful html template… But I am stuck in the Google Scriptlets, how to get variable Username and OTP from doPost function and send to html…
Here is my Code…
Code.js
function doPost(e) {
//this function will send emails from your gmail address
var recipient = e.parameters.recipient;
recipient = decodeURI(recipient);
var subject = e.parameters.subject;
subject = decodeURI(subject);
var body = e.parameters.body;
body = decodeURI(body);
var username = e.parameters.username;
username = decodeURI(username);
var otp = e.parameters.otp;
otp = decodeURI(otp)
var htmlTemplates = HtmlService.createTemplateFromFile('myMail');
var htmlBody = htmlTemplate.evaluate().getContent();
MailApp.sendEmail({to: recipient, subject: subject, otp: otp, htmlBody: htmlBody});
}
myMail.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<div style="font-family: Helvetica,Arial,sans-serif;min-width:1000px;overflow:auto;line-height:2">
<div style="margin:50px auto;width:80%;padding:20px 0">
<div style="border-bottom:5px solid #eee">
<a href="" style="font-size:30px;color: #f7c800;text-decoration:none;font-weight:600">AppName</a>
</div>
<p style="font-size:15px">Hello <?= username ?>,</p>
<p>Thank you for choosing Appname. Use this OTP to complete your Sign Up procedures and verify your account on AppName.</p>
<p>Remember, Never share this OTP with anyone.</p>
<h2 style="background: #00466a;margin: 0 auto;width: max-content;padding: 0 10px;color: #fff;border-radius: 4px;"><?= otp ?></h2>
<p style="font-size:15px;">Regards,<br />Team AppName</p>
<hr style="border:none;border-top:5px solid #eee" />
<div style="float:right;padding:8px 0;color:#aaa;font-size:0.8em;line-height:1;font-weight:300">
<p>App Name Inc</p>
<p>address</p>
</div>
</div>
</div>
</body>
</html>
I have read it already…
But I am facing trouble in doPost function, when url parameters are given from web component of kodular. I am not able to assign those parameters to html file…
Have you correctly published and updated your google apps script web app, & checked that your script url matches the one in the apps script deployment ?
Thank You guys for your involvement…
I got the solution…
Instead of using e parameters seperately, I use JSON stringify and JSON parse
It worked fine for me…
If anyone need help with the code then please mention, I will post…
THANK YOU!