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

199
Views
Cómo obtener una variable de la función doPost para pasar a la plantilla Html

Hola chicos, estaba creando una plantilla OTP de correo electrónico usando la función doPost en los scripts de Google. En realidad, tengo una aplicación en la que cuando el usuario solicita OTP, sus detalles como nombre, correo electrónico y OTP generado por la aplicación se envían a este script. Luego envía el correo electrónico al usuario. Pero pensé en implementar una hermosa plantilla html. Pero estoy atascado en Google Scriptlets, cómo obtener un nombre de usuario variable y OTP de la función doPost y enviar a html ...

Aquí está mi código ..

Código.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>

por favor ayudame.. te lo agradeceria

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

0

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

Referencia:

Empujar variables a plantillas

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!