简体   繁体   English

使用按钮从Google电子表格发送HTML电子邮件

[英]Send HTML email from google spreadsheet using a button

I am new to stack overflow and am looking for some advice and some guidance on a google spreadsheet i have been working on. 我是堆栈溢出的新手,正在寻找我一直在研究的Google电子表格的一些建议和指导。

A demo of it can be found at 可以在下面找到它的演示

https://docs.google.com/spreadsheets/d/1t9WfcG_1_mAavpN0l3v58JdD04Y1lL3PhAEoTUkq0Z4/edit?usp=sharing https://docs.google.com/spreadsheets/d/1t9WfcG_1_mAavpN0l3v58JdD04Y1lL3PhAEoTUkq0Z4/edit?usp=sharing

Basically the jist of it is that i require the following. 基本上,它的关键是我需要以下内容。

A sendEmail button in the tool bar at the top that will send a html formatted email to any email on the active page in a specific colour. 顶部工具栏中的sendEmail按钮,它将以特定颜色将html格式的电子邮件发送到活动页面上的任何电子邮件。

Essentially this is to allow me to send reminder to clients in groups and by colour status. 实质上,这是允许我按组和颜色状态向客户发送提醒。 Currently i have to mail each client individually using a canned response which is pretty time consuming. 目前,我必须使用罐头回复分别邮寄每个客户,这非常耗时。

So far i am using the following script as a basis, i can successfully send an email but i run into errors if email fields are empty. 到目前为止,我使用以下脚本作为基础,我可以成功发送电子邮件,但是如果电子邮件字段为空,则会遇到错误。 I am looking for it to overlook the empty fields and continue searching for an email address. 我正在寻找它来忽略空白字段,并继续搜索电子邮件地址。 Also i can only get it to locate a template of an active sheet but would require it to locate a template of another sheet and use that. 我也只能让它找到一个活动工作表的模板,但会要求它找到另一个工作表的模板并使用它。 Finally when i try adding in HTML the script successfully picks up the template but sends it as plain text and its not sent as HTML. 最终,当我尝试添加HTML时,脚本成功获取了模板,但将其以纯文本格式发送,而不是以HTML格式发送。

function sendEmails() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2;  // First row of data to process
  var numRows = 100;   // Number of rows to process
  // Fetch the range of cells A2:B3
  var dataRange = sheet.getRange(startRow, 1, numRows, 100)
  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (i in data) {
    var row = data[i];
    var emailAddress = row[8];  // Eight column
    var message = row[15];       // Fifteenth column
    var subject = "Welcome To Phorest";
    MailApp.sendEmail(emailAddress, subject, message);
  }
}

Looking forward to speaking with someone that can help me work all this out and save me some data entry in the process. 期待与可以帮助我解决所有问题并在此过程中节省一些数据输入的人交谈。

Appreciated. 感激。

You can send an HTML-containing email the following way: 您可以通过以下方式发送包含HTML的电子邮件:

var email = "some@email.com";
var subject = "Hello!";
var html = '<p> What is your favourite fruit? </p> <br>' +
           '<select>' +
           '<option value="apple">Apple</option>' +
           '<option value="orange">Orange</option>' +
           '</select> ';
MailApp.sendEmail({
      to: email,
      subject: subject,
      htmlBody: html
      });

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM