我在Google应用脚本中运行以下脚本(emailAddress是从表单中提取的变量):
MailApp.sendEmail(emailAddress, subject, message,{htmlBody:message});
我正在尝试为此添加cc和/或bcc字符串,但是当我这样做(并且我使用正确的格式)时,我得到一个一致的错误,即当我这样做时有太多的字符串。
MailApp.sendEmail仅限于四个字符串吗?我使用{htmlBody:message}的问题是什么?我能够通过消除这一点来部分实现我想要做的事情,但我的目标是发送一封html电子邮件并将该电子邮件复制到内部地址,以便我的所有员工都可以看到发送的电子邮件,而不仅仅是发件人。
另一个问题是我不想要以下
var emailSent = row[5];
if (emailSent != "EMAIL_SENT")
对cc' d和/或bcc&d;电子邮件或我的源表进行操作将为每封电子邮件包含两个EMAIL_SENT条目。
有解决方案吗?
答案 0 :(得分:5)
请试试这个:
MailApp.sendEmail(emailAddress, subject, message, {
htmlBody: message,
cc: 'internal1@email.com',
bcc: 'internal2@email.com'
});
此处还有其他参数可供选择:https://developers.google.com/apps-script/reference/mail/mail-app#sendemailrecipient-subject-body-options
答案 1 :(得分:1)
function myFunction(){
// html email
var htmlEmailBody = HtmlService.createTemplateFromFile('html-template-name');
// email title
var subject = "your title here..";
// this must be set or .sendEmail will not work. You can insert your own email address to get a copy of the email or just let it blank. Alternative you can delete bcc and just the emailAddress value to send 1 email only.
var emailAddress = "";
// same like emailAddress this must be set aswell. You can just keep it blank and use htmlBody for your html email. Alternative delete htmlBody and use normalBody for plain text email instead.
var normalBody = "";
MailApp.sendEmail(emailAddress, subject, normalBody, {
htmlBody: htmlEmailBody.evaluate().getContent(),
bcc: 'sample1@gmail.com,sample2@web.de'
});
}
答案 2 :(得分:0)
您可以将以下语法用于HTML模板。
/**
* Send email with CC
* @param {string} email - to email address
* @param {string} cc_email - cc email address
* @param {string} email_subject - subject of the email
* @param {string} from_name - email will appear to be from this name
* @param {string} template_name - name of HTML template
*/
function sendEmail(email, cc_email, email_subject, from_name, template_name) {
var templ = HtmlService.createTemplateFromFile(template_name);
var message = templ.evaluate().getContent();
MailApp.sendEmail({
to: email,
cc: cc_email,
subject: email_subject,
htmlBody: message,
name: from_name
});
}
这是MailApp.sendEmail的正式文档,带有高级选项: https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(String,String,String,Object)