在电子邮件正文中通过googlescript发送大胆的特定字词 [英] bold specific word in email body while sending it through googlescript
问题描述
ABCD
1名称电子邮件标识状态
2 Alex ax@gmail.com ERT ER A
3 Micke miike477@gmail.com Ejyu er w
4 John john7788@tri.com Arb Ed C
我在 D
列中有一个下拉列表(让A,B&例如C),现在我希望在列 D
D 将为空) >针对特定的名称
而不是自动电子邮件触发器到下面提到的 B
列中提到的电子邮件ID发件人ID和内容。
在列 D
中的值发生更改时,应该触发电子邮件,如果以前的值是B,现在它变成C,比邮件应该被触发。
CC-test1 @ gmail.com,test2 @ gmail.com
电子邮件正文:
你好Alex(应该从列A中选取,取决于哪个名称的电子邮件触发器
)
这里有一句话。
这里有一些句子与你的 ERT ER (应该从列C中选择
)具有状态 A ( 应该从列D
中选择)。
问候,
示例
123456789
我正在尝试使用下面提到的脚本(工作正常,只需要标识符
和 status
在电子邮件正文中):
function sendEmailToUser事件){
var eventRange = event.range;
var sheet = eventRange.getSheet();
var sheetName = sheet.getName();
var column = eventRange.getColumn();
if(sheetName ==Sheet1&& column == 4){//确保编辑的列位于正确的工作表中,否则编辑Sheet3中的列D可能会触发此
var row = eventRange.getRow(); //你需要知道哪一行,所以你可以发送电子邮件给正确的人
var rowValues = sheet.getRange(row,1,1,4).getValues();
var name = rowValues [0] [0];
var sendTo = rowValues [0] [1];
var identifier = rowValues [0] [2];
var status = rowValues [0] [3];
if(status!=){//状态为空时不发送邮件
var cc =test1@example.com,test2@example.com;
var subject =什么是:+标识符;
var content =Hi+ name +\\\
+ status +的值是+ identifier +的值吗?
MailApp.sendEmail(sendTo,subject,content,{
cc:cc
});
你在混合你的单引号和双引号,并且不能正确地连接它们。请查看 Javascript字符串。
<要连接
'< body>
和Hi
,您需要包含 +
操作符,因为它们是两个单独的字符串: '< body>'+嗨
但,' < body>'
和Hi
是不必要的,只需将它写成
< body>嗨
这是你应该做什么:
var content =Hi+ name +\\\
什么是值+ identifier + 状态为+ status +?;
var contentHTML =< body>< p> Hi+ name +< / p>< br>< p>什么是< b> +标识符+< / b>与状态< b> + status +< / b>?< / p>< / body>;
MailApp.sendEmail(sendTo,subject,content,{
cc:cc,
htmlBody:contentHTML
});
content
将显示纯文本未格式化)的电子邮件客户端(或个人喜好)不显示HTML电子邮件的用户的文本。 contentHTML
是相同的,但显示HTML格式的内容。
I am using a google spreadsheet which looks like:
A B C D
1 Name e-mail Identifer Status
2 Alex ax@gmail.com ERT ER A
3 Micke miike477@gmail.com Ejyu er w
4 John john7788@tri.com Arb Ed C
I have a drop down list in column D
(let say A,B & C for example), now i want that whenever the value changes (Initially the column D
would be blank) in column D
against a particular Name
than an automatic e-mail trigger to e-mail id mentioned in column B
by below mentioned sender id and content.
The email should be trigger whenever value changes in column D
except for the blank, and if there were previously value was "B" and now it change to "C" than mail should be trigger.
Sender-example@gmail.com
CC-test1@gmail.com,test2@gmail.com
E-mail Body:
Hi Alex (Should be picked from column A depending against which name e-mail trigger
)
some sentence here.
some sentence here with your ERT ER (Should be pick from column C
) has status A (should be pick from column D
).
Regards,
example
123456789
I am trying using below mentioned script (which is working fine just want to bold value of identifier
and status
in e-mail body):
function sendEmailToUser(event){
var eventRange = event.range;
var sheet = eventRange.getSheet();
var sheetName = sheet.getName();
var column = eventRange.getColumn();
if (sheetName == "Sheet1" && column == 4){ // Make sure the edited column is in the correct sheet, otherwise editing Column D in Sheet3 might trigger this
var row = eventRange.getRow(); // You need to know which row so you can send the email to the correct person
var rowValues = sheet.getRange(row, 1, 1, 4).getValues();
var name = rowValues[0][0];
var sendTo = rowValues[0][1];
var identifier = rowValues[0][2];
var status = rowValues[0][3];
if (status != "") { // Don't send the email if the status is blank
var cc = "test1@example.com, test2@example.com";
var subject = "What is the: " + identifier;
var content = "Hi " + name + "\nWhat is the value " + identifier + " with the status " + status + "?";
MailApp.sendEmail(sendTo, subject, content, {
cc: cc
});
}
}
}
You're mixing up your single and double quotes and also not concatenating them correctly. Please review Javascript Strings.
To concatenate '<body>
and "Hi"
, you need to include the +
operator as they're two separate strings:
'<body>' + "Hi"
BUT, the concatenation of '<body>'
and "Hi"
is unnecessary when you can simply write it as
"<body>Hi"
This is what you should be doing:
var content = "Hi " + name + "\nWhat is the value " + identifier + " with the status " + status + "?";
var contentHTML = "<body><p>Hi " + name + "</p><br><p>What is the value <b>" + identifier + "</b> with the status <b>" + status + "</b>?</p></body>";
MailApp.sendEmail(sendTo, subject, content, {
cc: cc,
htmlBody: contentHTML
});
content
Will display the plain-text (unformatted) text for those users whose email clients (or by personal preference) do not display HTML email. contentHTML
is the same, but shows the HTML formatted content.
这篇关于在电子邮件正文中通过googlescript发送大胆的特定字词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!