Googlesheets:我需要为文本框分配一个脚本,该脚本将电子邮件发送到位于另一个电子表格中的电子邮件地址

时间:2017-04-17 02:12:41

标签: email google-apps-script google-sheets

我确信这对某些人来说是一个令人沮丧的帖子,我很抱歉。我没有任何编码背景,这将是我尝试过的第一个脚本之一。再次感谢您的帮助!

我需要完成的是将脚本分配给文本框,该文本框发送的电子邮件的地址位于另一个电子表格中。

以下是设置:图片1.这是电子表格和标签,我希望使用位于“游戏内名称”右侧的文本框(带有E)发送电子邮件地址

图片1.)http://imgur.com/a/8nVzl

“游戏内名称”已从单独的电子表格中导入。我有这个单独的电子表格的网址,位于当前电子表格的单独标签中,如图2所示。

图片2(左侧)和图片3(右侧)因为我的声誉不是10:http://imgur.com/a/q2bsH

您可以从图片3中的第二个电子表格(“游戏内名称”和“声望”)中查看我正在导入的数据。但我不希望以这种方式导入电子邮件地址。

我想要一个脚本从主电子表格发送电子邮件,然后使用“播放器密钥输入”标签中的电子表格密钥网址从第二个电子邮件地址中提取电子邮件地址。

我有一个试图完成此操作的代码示例,目前仅作为喜剧缓解来解决这个问题。

如果这是一个写得不好/解释不好的问题,我很抱歉。我编码很糟糕。我非常感谢任何意见!

2 个答案:

答案 0 :(得分:1)

问题"从另一个电子表格中提取电子邮件地址"我会用一个公式来复制它。然后分配一个脚本通过电子邮件发送地址我不确定你如何通过脚本从另一张表中提取信息。

以下公式会将A1中的电子表格数据提取到您指定的单元格。

=IMPORTRANGE("YOURSHEETID","Sheet1!A1:A")

答案 1 :(得分:1)

我们能够使用此脚本实现此功能:

    /**
 * This is a utility function that sends an email.
 * It requires a To address, a Subject, and the message Body.
 */
function sendEmail(to, subject, body) {
  // The Reply To address is the default address that appears when a user replies to the email.
  // If not set to a bogus email, it probably defaults to the owner of the sheet!
  var replyTo = "donotreply@mail.com"

  // Send the email!
  MailApp.sendEmail(to, replyTo, subject, body)
}


/**
 * This function is an example of a boilerplate message that you can send.
 * You could duplicate this function for other types of messages.
 */
function sendAllianceMessageToUser(row) {
  var user = getUserInfoFromRow(row);

  sendEmail(user.email, "MCOC Alert", user.name+",\n\nPlease log on to MCOC and check AQ/AW!");
}


/**
 * This utility function will retrieve a user's info when supplied with a row number.
 * The row number must match the rows on the "Roster/Prestige" sheet.
 * This function will not need to change unless the structure of the sheets change.
 */
function getUserInfoFromRow(row) {
  // Keep a reference to the current active sheet
  //var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.openById('1McfUWHPCgh7XWtLgZX6mcnLs_o1MQprBOKbHiwNsVEo').getSheetByName('Roster/Prestige');

  // Grab the sheet key in the row that was provided. (In this case, column L)
  //var skey = sheet.getRange('L'+row).getValue();
  var skey = sheet.getRange('L4').getValue();

  Logger.log(skey);

  // Open the remote sheet using the ID that was retrieved earlier.
  var remote = SpreadsheetApp.openById(skey).getSheetByName('Sheet1');
  // Grab the necessary cell values
  var ign   = remote.getRange('C2').getValue();
  var email = remote.getRange('C4').getValue();

  var user = new Object();
  user.name = ign;
  user.email = email;
  user.sheet_key = skey;

  return user;
}


/**
 * These functions are generic image click handlers for each image.
 * Each image will call a function based on which row it is placed over.
 * MOVING IMAGES WILL BREAK THIS!
 */
function row3_clicked() { sendAllianceMessageToUser('3'); }
function row4_clicked() { sendAllianceMessageToUser('4'); }
function row5_clicked() { sendAllianceMessageToUser('5'); }
function row6_clicked() { sendAllianceMessageToUser('6'); }
function row7_clicked() { sendAllianceMessageToUser('7'); }
function row8_clicked() { sendAllianceMessageToUser('8'); }
function row9_clicked() { sendAllianceMessageToUser('9'); }
function row10_clicked() { sendAllianceMessageToUser('10'); }
function row11_clicked() { sendAllianceMessageToUser('11'); }
function row12_clicked() { sendAllianceMessageToUser('12'); }
function row13_clicked() { sendAllianceMessageToUser('13'); }
function row14_clicked() { sendAllianceMessageToUser('14'); }
function row15_clicked() { sendAllianceMessageToUser('15'); }
function row16_clicked() { sendAllianceMessageToUser('16'); }
function row17_clicked() { sendAllianceMessageToUser('17'); }
function row18_clicked() { sendAllianceMessageToUser('18'); }
function row19_clicked() { sendAllianceMessageToUser('19'); }
function row20_clicked() { sendAllianceMessageToUser('20'); }
function row21_clicked() { sendAllianceMessageToUser('21'); }
function row22_clicked() { sendAllianceMessageToUser('22'); }
function row23_clicked() { sendAllianceMessageToUser('23'); }
function row24_clicked() { sendAllianceMessageToUser('24'); }
function row25_clicked() { sendAllianceMessageToUser('25'); }
function row26_clicked() { sendAllianceMessageToUser('26'); }
function row27_clicked() { sendAllianceMessageToUser('27'); }
function row28_clicked() { sendAllianceMessageToUser('28'); }
function row29_clicked() { sendAllianceMessageToUser('29'); }
function row30_clicked() { sendAllianceMessageToUser('30'); }
function row31_clicked() { sendAllianceMessageToUser('31'); }
function row32_clicked() { sendAllianceMessageToUser('32'); }

function test() {
  sendAllianceMessageToUser('4'); // Testing!
}