简体   繁体   English

是否可以仅使用 JavaScript 而不使用 HTML 将动态链接插入到电子邮件中? (使用 Google Script 发送电子邮件)

[英]Is it possible to insert a dynamic link into an email using only JavaScript and no HTML? (Using Google Script to sent the email)

Need to preface this with an edit, I'm not using Javascript in the actual email.需要先进行编辑,我没有在实际的电子邮件中使用 Javascript。 I'm using Javascript in Google Script which I run to send the email.我在 Google Script 中使用 Javascript 来发送电子邮件。

I don't really know anything about using html/js in emails, but my roommate needed help inserting a dynamic link using JavaScript into his email using Google Sheets (a .gs file), so I found the code to do it, but the problem is the JavaScript still uses HTML for the dynamic link.我对在电子邮件中使用 html/js 一无所知,但我的室友需要帮助,使用 Google 表格(.gs 文件)将使用 JavaScript 的动态链接插入到他的电子邮件中,所以我找到了执行此操作的代码,但是问题是 JavaScript 仍然使用 HTML 作为动态链接。

What I found was this我发现的是这个

var str = "TEXT FOR LINK"
var link = str.link("http://LINKGOESHERE")

Running this works perfectly as it should.运行它可以正常工作。 However, the rest of his email was entirely JavaScript, so JavaScript used this code to insert the following HTML code:但是,他的电子邮件的其余部分完全是 JavaScript,因此 JavaScript 使用此代码插入以下 HTML 代码:

<a href="http://LINKGOESHERE">TEXT FOR LINK</a>

Since we are running this as a .gs file (Google Sheets), I was wondering if there was a way of just inserting the dynamic link without using any HTML at all, or if we simply need to wrap everything in HTML (and if so, how does that work with an email being sent by running a .gs file).由于我们将它作为 .gs 文件(Google Sheets)运行,我想知道是否有一种方法可以在不使用任何 HTML 的情况下插入动态链接,或者我们是否只需要将所有内容都包装在 HTML 中(如果是这样) ,这如何处理通过运行 .gs 文件发送的电子邮件)。

Here is what the .gs file looks like with the main text and info replaced with gibberish:以下是 .gs 文件的样子,主要文本和信息被乱码替换:

function sendEmails() {
var str = "TEXT FOR LINK"
var link = str.link("http://LINKGOESHERE")

var senderEmail = 'SOMEONESEMAILADDRESS@email.com';
link.onclick = function() {
    this.href = "mailto:"+senderEmail;
};
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2; 
  var numRows = sheet.getLastRow()-1;
  var dataRange = sheet.getRange(startRow, 1, numRows, 2);
  var data = dataRange.getValues();

  var sender = 'MyName';
  var body = '\n\nTEXT BLABLABLABLABLA'+link+' TEXTBLABLABLABLA';
  var subject = 'SUBJECT';
  var options = {replyTo: senderEmail , from: senderEmail, name: sender};

  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var emailAddress = row[0];
    var firstName = row[1];
    var message = 'Hi ' + firstName + ',' + body;


    MailApp.sendEmail(emailAddress, subject, message, options);
  }
}

You should not use javascript inside your emails.您不应在电子邮件中使用 javascript。 Most email clients do not allow execution of javascript since it is a strong security vulnerability.大多数电子邮件客户端不允许执行 javascript,因为它是一个强大的安全漏洞。 Some email clients like Outlook for example allowed it, but I am not sure if it still does or not.例如,某些电子邮件客户端(例如 Outlook)允许它,但我不确定它是否仍然允许。

Well even if there exists a client that runs javascript, sending emails with javascript is a huge red flag and your emails will be mostly rejected by mail servers.好吧,即使存在运行 javascript 的客户端,使用 javascript 发送电子邮件也是一个巨大的危险信号,您的电子邮件大多会被邮件服务器拒绝。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在使用Powershell脚本发送到Outlook的电子邮件中插入有效的HTML按钮 - How to insert a working HTML button in an email sent by using Powershell script to Outlook 使用HTML和JavaScript的电子邮件 - Email Using HTML and JavaScript 使用Javascript通过Link通过电子邮件发送内容 - Email a content with Link using Javascript 使用谷歌应用脚本从 email 文本中删除超链接 - Removing Hyper link from an email text using google apps script 使用脚本编辑器将谷歌表格中的表情符号 unicode 插入 email - Insert Emoji unicode from google sheets to an email using script editor 如何使用Google Apps脚本和JavaScript在HTML表单字段中自动显示用户电子邮件 - How to automatically display a user email in an HTML form field using Google Apps Script and JavaScript 如何使用JavaScript在HTML电子邮件中显示动态参数? - How to display dynamic parameters in an HTML Email using javascript? 如何使用 HTML 发送 Google App 脚本 email - How do I send Google App Script email using HTML 如何仅注册使用 Firebase javascript 中的电子邮件链接验证其电子邮件地址的用户? - How to sign up only the users who have verified thier email addresses using the email link in Firebase javascript? 使用JavaScript显示电子邮件的引荐链接 - Display referral link to email using javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM