Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

188
Vistas
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 Respuestas
Responde la pregunta

0

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

Reference:

Pushing variables to templates

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda