我已经搜索了但找不到任何示例
我发送的是
//Send Email
var emailContents =
{
to: techManagerEmail+","+organiserEmail,
subject: "New Technical Support Request for " + eventName,
body: "Event Name: "+eventName+ "\n\n"+"Event Room: "+eventRoom+ "\n\n"+eventDescription +"\n\n"+ allEvents + "\n\n" + "Google Folder: "+newFolderLink+"\n \n"+techTeam+" Calendar Link: "+ calendarLink + "\n\n" + "Date Submitted: " + submitionDate + " by: " + submitterEmail,
};
MailApp.sendEmail(emailContents);
}
当我发送时,当我希望填写表单的人成为发件人时,它以创建表单(me)的用户身份发送-(我也希望填写表单的人成为日历事件的创建者,但我认为这可能是一个更大的问题)。能够更改显示名称也很好。
我看过api sendAs选项,但是正在努力找出如何使用它或语法。
任何建议将不胜感激。
根据要求,提供完整代码:
function onSubmit(e)
{
//Set General Variables
var formResponses = e.response.getItemResponses();
var submitterEmail = e.response.getRespondentEmail();
var submitionDate = e.response.getTimestamp();
var eventName = formResponses[0].getResponse();
var eventDescription = formResponses[1].getResponse();
var moduleCode = formResponses[2].getResponse();
var noStudents = formResponses[3].getResponse();
var organiser = formResponses[4].getResponse();
var organiserEmail = formResponses[5].getResponse();
var eventRoom = formResponses[6].getResponse();
var techTeam = formResponses[7].getResponse();
var supportRequired = formResponses[8].getResponse();
var supportDescription = formResponses[9].getResponse();
var equipmentRequired = formResponses[10].getResponse();
var startDate = formResponses[11].getResponse();
var nextAction = formResponses[18].getResponse();
var supportDateNo = 11;
var supportStartNo = 12;
var eventStartNo = 13;
var eventEndNo = 14;
var supportEndNo = 15;
var eventDaysDataNo = 16;
var eventEndDateNo = 17;
var nextActionNo = 18;
var nextActionSwitch = 1;
var loopNo = 1;
var calendarId = CalendarApp.getCalendarById(calId);
var allEvents ="";
var day = 1000*60*60*24
var eventDescription = 'Organiser: ' + organiser + '\n \n' +
'Module Code: ' + moduleCode + '\n \n' +
'Description of the Event: ' + eventDescription + '\n \n' +
'Type of support: ' + supportRequired + '\n \n' +
'Description of Support: ' + supportDescription + '\n \n'+
'Number of Students: ' + noStudents + '\n \n'+
'Equipment Required: ' + equipmentRequired + '\n\n';
//General Operations
if(organiserEmail==""){var organiserEmail = submitterEmail};
if(techTeam=="Performance Studios")
{
var calId = "****";
var techManagerEmail = "****";
var calendarLink = "****";
var parentFolder = DriveApp.getFolderById('****');
};
if(techTeam=="****")
{
var calId = "****";
var techManagerEmail = "****";
var calendarLink = "****";
var parentFolder = DriveApp.getFolderById('****');
};
if(techTeam=="****")
{
var calId = "****";
var techManagerEmail = "****";
var calendarLink = "****";
var parentFolder = DriveApp.getFolderById('****');
};
if(techTeam=="****")
{
var calId = "****";
var techManagerEmail = "****";
var calendarLink = "****";
var parentFolder = DriveApp.getFolderById('****');
};
//create attachments
var folderName = startDate + ' ' + eventName
var newFolder = parentFolder.createFolder(folderName).getId();
var newFolderLink = DriveApp.getFolderById(newFolder).getUrl();
//Calendar Creation Loop
while(nextActionSwitch==1)
{
//Set Variables
var supportDate = formResponses[supportDateNo].getResponse();
var supportStart = formResponses[supportStartNo].getResponse();
var eventStart = formResponses[eventStartNo].getResponse();
var eventEnd = formResponses[eventEndNo].getResponse();
var supportEnd = formResponses[supportEndNo].getResponse();
var eventDaysData = formResponses[eventDaysDataNo].getResponse();
var eventEndDate = formResponses[eventEndDateNo].getResponse();
var nextAction = formResponses[nextActionNo].getResponse();
var indivudualTechDetails = "";
var individualEventDetails = "";
var individualRepeatDetails = "";
//Time Operations
var eventEndDate = eventEndDate.replace(/-/g, "");
if (eventDaysData == "All"){var eventDaysData = "MO,TU,WE,TH,FR,SA,SU,"};
if (eventDaysData =="No Repeat"){var eventDaysData = ""; var eventEndDate = ""};
if (eventEndDate == ""){var eventDaysData = ""};
var alteredEndDate = Number(eventEndDate)+1;
var startDateTime = new Date(supportDate+"T"+supportStart+":00");
var endDateTime = new Date(supportDate+"T"+supportEnd+":00.000Z");
if (endDateTime<=startDateTime){var endDateTime = new Date(endDateTime.getTime() + day)};
var start = Utilities.formatDate(startDateTime, "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
var end = Utilities.formatDate(endDateTime, "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");
var finalDescription = eventDescription;
if (eventStart!=""){var finalDescription = eventName + ' Start Time: ' + eventStart +'\n' + eventName + ' End Time: ' + eventEnd + '\n \n' + eventDescription};
//Date Display Operations
var eventDay = startDateTime.getDate();
var eventMonth = startDateTime.getMonth()+1;
var eventYear = startDateTime.getFullYear();
var eventEmailDate = eventDay+"/"+eventMonth+"/"+eventYear;
var repeatEndDate = new Date(eventEndDate+"T"+supportStart+":000Z");
var eventEndDay = repeatEndDate.getDate();
var eventEndMonth = repeatEndDate.getMonth()+1;
var eventEndYear = repeatEndDate.getFullYear();
var eventEmailEndDate = eventEndDay+"/"+eventEndMonth+"/"+eventEndYear;
//Create Event
var event =
{
summary: eventName,
location: eventRoom,
start: {dateTime: start, timeZone: "GMT"},
end: {dateTime: end, timeZone: "GMT"},
description: finalDescription,
colorId: 8,
attendees: [{email: submitterEmail}, {email:organiserEmail}],
attachments: [{fileId: newFolder, fileUrl:newFolderLink, title: eventName+" Folder"}],
"recurrence": ["RRULE:FREQ=DAILY;UNTIL="+alteredEndDate+";BYDAY="+eventDaysData]
};
if (eventEndDate == ""|| eventDaysData == "No Repeat")
{
var event =
{
summary: eventName,
location: eventRoom,
start: {dateTime: start, timeZone: "GMT"},
end: {dateTime: end, timeZone: "GMT"},
description: finalDescription,
colorId: 8,
attendees: [{email: submitterEmail}, {email:organiserEmail}],
attachments: [{fileId: newFolder, fileUrl:newFolderLink, title: eventName+" Folder"}],
};
};
var eventLink = Calendar.Events.insert(event, calId, {SendNotifications: true, supportsAttachments:true}).getHtmlLink();
//Event Details
var individualTechDetails =
"Instance: " + loopNo + "\n\n" +
"Start Date: " + eventEmailDate + "\n\n" +
"Tech Start Time: " + supportStart + "\n\n" +
"Tech End Time: " + supportEnd + "\n\n";
if (eventStart != ""){var individualEventDetails =
"Event Start Time: " + eventStart + "\n\n" +
"Event End Time: " + eventEnd + "\n\n"};
if (eventEndDate != ""){ var individualRepeatDetails =
"Repeats: " + eventDaysData + "\n\n"+
"End Date: " + eventEndDate+"\n\n"};
var combinedEventDetails = individualTechDetails + individualEventDetails + individualRepeatDetails + "Event Link: "+ eventLink;
var allEvents = allEvents + combinedEventDetails + "\n\n -- \n \n";
//Set Loop Values
var nextActionSwitch = 0;
if (nextAction=="Add dates with a different pattern")
{
var nextActionSwitch = 1;
var loopNo = loopNo +1;
var supportDateNo = supportDateNo +8;
var supportStartNo = supportStartNo +8;
var eventStartNo = eventStartNo +8;
var eventEndNo = eventEndNo +8;
var supportEndNo = supportEndNo +8;
var eventDaysDataNo = eventDaysDataNo +8;
var eventEndDateNo = eventEndDateNo +8;
var nextActionNo = nextActionNo +8;
};
};
//Send Email
var requestorEmails = submitterEmail + ", " + organiserEmail;
if (organiserEmail == submitterEmail){requestorEmails = organiserEmail};
var emailContents =
{
to: techManagerEmail+","+requestorEmails,
subject: "New Technical Support Request for " + eventName,
body: "Event Name: "+eventName+ "\n\n"+"Event Room: "+eventRoom+ "\n\n"+eventDescription +"\n\n"+ allEvents + "\n\n" + "Google Folder: "+newFolderLink+"\n \n"+techTeam+" Calendar Link: "+ calendarLink + "\n\n" + "To create another event: ****" + "\n\n" + "Date Submitted: " + submitionDate + " by: " + submitterEmail,
name: techTeam + " Technical Support Requests",
};
MailApp.sendEmail(emailContents);
}
答案 0 :(得分:0)
实现此目标的方法有限。实现此目的的唯一方法是使用填写表单的人员的帐户登录。如果您是通过触发器自动运行脚本的,只需使用此帐户设置触发器即可。
Apps Script跟踪器上存在与此相关的未解决问题: Issue Tracker
希望这能回答您的问题!