Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
How to get variable from doPost function to pass to Html Template

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.gs

 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});
}

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>

Please help me.. I would be thankful to you

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

var htmlTemplates = HtmlService.createTemplateFromFile('myMail');
htmlTemplates.username = username;
htmlTemplates.otp = otp;

Reference:

Pushing variables to templates

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!