我们可以在云功能中使用脚本标签吗

时间:2020-02-29 11:47:40

标签: html node.js google-cloud-functions

我正在使用mailOptions在云功能的http请求中发送电子邮件,我包含了html代码,它工作正常,基于条件我应该隐藏一个表格行来实现它,我正在使用脚本标签并在其中写入了隐藏条件,但是问题是它不起作用,我在脚本标签中写了一个控制台语句,它也不起作用..我们可以在云函数中使用脚本标签吗?。任何人都可以帮帮我。

var mailOptions = {
                 from: 'abcd@gmail.com',
                 to: email,
                 subject: 'mail',
                 text: + 'welcome',
                 html: `<!DOCTYPE html>
                 <html lang="en">

                 <head>
                   <meta charset="utf-8">
                   <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
                   <meta http-equiv="X-UA-Compatible" content="IE=edge" />
                   <meta name="format-detection" content="date=no" />
                   <meta name="format-detection" content="address=no" />
                   <meta name="format-detection" content="telephone=no" />
                   <title>Email Template</title>
                   <link href="https://fonts.googleapis.com/css?family=Poppins:200,200i,300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">

                 </head>
                 <body>

                 <div style="padding: 60px 0 !important; margin: 0 !important; display: block !important; background: #745de9; font-family: 'Poppins', sans-serif; font-size: 15px; color: #595959;">
                     <div style="width: 660px; margin: auto; background-color: #ffffff">
                         <div style="margin: 0 0 0 0; padding: 30px 30px 40px 30px;">
                             <div style="width: 35%; float: left;">
                                 <img src="abc.png" alt="" style="width: 100%"/>
                             </div>
                             <div style="float: right; border-bottom: solid 1px #dbdbdb; width: 100%; padding: 3px 0 8px 0; width: 62%; text-align: right">
                                 <a style="color: #fb7af5; text-decoration: none; font-family: 'Poppins', sans-serif; font-size: 15px;" href="https://example.com/">VisitUs</a> <span style="padding: 0 5px; color: rgb(201, 201, 201)">-</span>
                                 <a style="color: #fb7af5; text-decoration: none; font-family: 'Poppins', sans-serif; font-size: 15px;" href="https://example1/">Blog</a>
                             </div>
                         </div>

                         <div style="padding: 0px 30px 30px 30px;">
                             <div style="text-align: right; padding: 20px 20px 10px 20px; background-color:#f7f7f7; margin: 20px 0 30px 0;">
                                 <h3 style="margin-bottom: 10px; color: #595959; font-size: 20px; font-family: 'Poppins', sans-serif; font-size:20px;">Order Confirmation</h3>
                                 <p style="font-family: 'Poppins', sans-serif; font-size: 15px; color: #595959;">Order #<a href="#" style="color: #fb7af5">` +  cid + `</a></p>
                             </div>
                             <h3 style="margin-bottom: 10px; font-family: 'Poppins', sans-serif; font-size: 20px; color: #ff721e">Hello `+ fname + " " +lname + `</h3>
                             <p style="font-family: 'Poppins', sans-serif; font-size: 15px; color: #595959;">Your order#<a href="#" style="color: #fb7af5">` + pn + `</a> has been placed</p>
                             <div class="hr-line"></div>
                             <h3 style="margin: 40px 0 5px 0; font-family: 'Poppins', sans-serif; font-size:20px; color: #595959">Order Details</h3>

                             <h3 style="margin: 40px 0 5px 0; font-family: 'Poppins', sans-serif; font-size:20px; color: #595959">For more details : ` + link +`</h3>
                             <div class="hr-line"></div>
                             <p style="margin-top: 15px">CancelID <a href="#" style="color: #fb7af5">` +  cid + `</a></p>
                             <p style="font-family: 'Poppins', sans-serif; font-size: 15px; color: #595959;">Placed on ` +  dt + `</p>
                             <div style="margin: 30px 0 0px 0;">
                                 <table style="width: 100%; margin-bottom: 1rem; color: #595959; line-height: 25px; border-collapse: collapse;">
                                     <tbody>
                                         <tr style="border-bottom: solid 1px #f0f0f0;">
                                             <td id="q" style="width: 20%"><img src= `+im+`  alt="" style="width: 100%; padding-bottom: 20px"/></td>
                                             <td id="w" style="width: 65%; text-align: left; vertical-align: top; padding-left: 10px">
                                                 <h3><a href="#" style="color: #fb7af5; font-family: 'Poppins', sans-serif; font-size:17px;">` + pn + `</a></h3>
                                             </td>
                                             <td id="e" style="text-align:right; width: 15%; vertical-align: top; font-family: 'Poppins', sans-serif; font-size: 15px; color: #595959;">` + refundprice +`</td>
                                         </tr>
                                         <tr>
                                             <td id="r" colspan="2" style="text-align:right; padding: 6px 10px; font-family: 'Poppins', sans-serif; font-size: 15px; color: #595959;">ProductPrice</td>
                                             <td id="t" style="text-align:right; padding: 6px 10px; font-family: 'Poppins', sans-serif; font-size: 15px; color: #595959;">` + pp + `</td>
                                         </tr>
                                         <tr>
                                             <td id="y" colspan="2" style="text-align:right; padding: 6px 10px; font-family: 'Poppins', sans-serif; font-size: 15px; color: #595959;">Tax</td>
                                             <td id="u" style="text-align:right; padding: 6px 10px; font-family: 'Poppins', sans-serif; font-size: 15px; color: #595959;">` + st + `</td>
                                         </tr>

                                         <tr>
                                         <td id="tag1" colspan="2" style="text-align:right; style="display:none; padding: 6px 10px; font-family: 'Poppins', sans-serif; font-size: 15px; color: #595959;">PersonalShopperPrice</td>
                                         <td  id="tag" style="text-align:right; style="display:none; padding: 6px 10px; font-family: 'Poppins', sans-serif; font-size: 15px; color: #595959;">` + psprice + `</td>
                                         </tr>
                                         <tr>
                                             <td id="i" colspan="2" style="text-align:right; background-color: #745DE9; color:#fff; padding: 6px 10px; font-family: 'Poppins', sans-serif; font-size: 15px; color: #ffffff;">TotalAmountPaid</td>
                                             <td id="o" style="text-align:right; background-color:#745DE9; color:#fff; padding: 6px 10px; font-family: 'Poppins', sans-serif; font-size: 15px;"><b>` + refundprice + `</b></td>
                                         </tr>
                                     </tbody>
                                 </table>

                             </div>
                         </div>
                     </div>
                 </div>
                  <script>
                        Console.log('entered in script');
                        var row = document.getElementById('tag');
                        row.style.display = 'none';
                  </script> 


                </body>

              </html>`,


            };


           transporter.sendMail(mailOptions, function(error, info){
                if (error) {
                    console.log(error);
                    res.status(200).send("error");
                } else {
                    console.log('Email sent: ' + info.response);
                    res.status(200).send("status");
                }
            });


     }

0 个答案:

没有答案