OnEdit需要从列发送电子邮件 [英] OnEdit need to send emails from a column

查看:72
本文介绍了OnEdit需要从列发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在O列中提到已发货"时,我想在C列中发送电子邮件(带有相应的行)

When in column O cell is mentioned "Shipped" I want to send emails in column C (with corresponding row)

需要支持才能正确设置此脚本

Need support to get this script right

function sendEmail(e) {
    var thisSheet = e.source.getActiveSheet();
    if (thisSheet.getName() !== 'CRM' || e.range.columnStart !== 15 || e.range.rowStart == 1 || e.value !== 'Shipped') return;
    var body, headers = thisSheet.getRange(1, 1, 1, 6)
        .getValues()[0],
        thisRow = thisSheet.getRange(e.range.rowStart, 1, 1, 6)
        .getValues()[0],
        recipientsEMail = (thisSheet.getRange.columnStart !==3 || e.range.rowStart ==1)
        .getValues()[0],
        recipients = recipientsEMail,
        subject = "Your Vehicle is shipped " + e.source.getName(),
        body = "",
        i = 0;
    while (i < 6) {
        body += headers[i] +' - ' + thisRow[i] +'\n';
        i++;
    }

    MailApp.sendEmail(recipients, subject, body);
}

我的工作表

推荐答案

查看是否可行:

function sendEmail(e) {
var thisSheet = e.source.getActiveSheet();
if (thisSheet.getName() !== 'CRM' || e.range.columnStart !== 15 || e.range.rowStart == 1 || e.value !== 'Shipped') return;
var body, headers = thisSheet.getRange(1, 1, 1, 15)
    .getValues()[0],
    thisRow = thisSheet.getRange(e.range.rowStart, 1, 1, 15)
    .getValues()[0];
    var recipients = thisRow[2];
    var subject = "Your Vehicle is shipped " + e.source.getName(),
    body = "Dear Customer,\n\nYour vehicle has been shipped from Japan";


MailApp.sendEmail(recipients, subject, body);
}

您没有说构造电子邮件正文需要使用多少列,但是如果您在while循环中增加数量,则可以轻松更改.

You didn't say how much columns you need to use to construct the body of the email but that can be easily changed if you increase the number in the while loop.

这篇关于OnEdit需要从列发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆