我在從另一個電子郵件地址(它是別名)的Google工作表中發送html正文消息時遇到問題。從其他電子郵件地址通過Google表格發送包含HTML正文的電子郵件
我可以使用mailApp發送它,但是當我切換到GmailApp時,我似乎無法使其工作。
我使用的腳本如下:
function sendNotification(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var row = sheet.getActiveRange().getRow();
var cellvalue = ss.getActiveCell().getValue().toString();
var emailAdd = "[email protected]";
if(event.range.getA1Notation().indexOf("G") > -1 && sheet.getRange("G" + row).getDisplayValue() > 999 && emailAdd.length > 1)
{
var rowVals = getActiveRowValues(sheet);
var aliases = GmailApp.getAliases();
Logger.log(aliases);
GmailApp.sendEmail(
"[email protected]",
"Allocation Request - " + rowVals.quantity + " cases on " + rowVals.date,
{htmlBody: "There has been a new allocation request from " + rowVals.name + " in the " + rowVals.team + " team.<br \> <br \> "
+ "<table border = \"1\" cellpadding=\"10\" cellspacing=\"0\"><tr><th>Issuing Depot</th><th>Delivery Date</th><th>Case Quantity</th></tr><tr><td>"+rowVals.depot+"</td><td>"+rowVals.date+"</td><td>"+rowVals.quantity+"</td></tr></table>"
+ "<br \>To view the full details of the request, use the link below.<br \> <br \>" +
"<a href=\"https://docs.google.com/spreadsheets\">Allocation Requests</a>"
+"<br \> <br \><i>This is an automated email. Please do not reply to it.<\i>"},
{from: aliases[0]}
);
}
}
function getActiveRowValues(sheet){
var cellRow = sheet.getActiveRange().getRow();
// get depot value
var depotCell = sheet.getRange("E" + cellRow);
var depot = depotCell.getDisplayValue();
// get date value
var dateCell = sheet.getRange("F" + cellRow);
var date = dateCell.getDisplayValue();
// get quantity value
var quantCell = sheet.getRange("G" + cellRow);
var quant = quantCell.getDisplayValue();
// return an object with your values
var nameCell = sheet.getRange("B" + cellRow);
var name = nameCell.getDisplayValue();
var teamCell = sheet.getRange("C" + cellRow);
var team = teamCell.getDisplayValue();
return {
depot: depot,
date: date,
quantity: quant,
name: name,
team: team
} }
我設法從我的別名發送電子郵件,但它只是發送和包含的消息[對象],而不是從它發送別名工作正常。
有人可以看看我做錯了嗎?我還沒有在這裏找到答案。謝謝。
有4個參數來sendEmail(收件人,主題,郵件正文,OPTIONS)你必須在電子郵件正文中的第三個參數選項對象。你可能犯了這個錯誤,因爲你試圖把所有東西放在一起。您應該爲選項對象和Html創建一個變量,以便sendEmail()更具可讀性。 –
謝謝,注意到我的錯誤。但是,如何將變量設置爲html正文? –
看到回答下面 –