英文:
Google Apps Script, Send Email with content bold
问题
以下是代码部分的中文翻译:
-
const Recipient = `test@gmail.com, test2@gmail.in`;
-
const Subject = `You got a new mail: ${Number}`;
-
const Body = `Dear User,\n\n 新邮件已收到:\n\n\ 编号: ${Number} \n\t姓名: ${name}\n\t电子邮件: ${email} \n\n祝 好,\n 名字`;
-
GmailApp.sendEmail(Recipient,Subject,Body);
英文:
Here I'm sending mail using google apps script and it's working fine. but in email body in need some message in bold i.e, ${Number}
-
const Recipient = `test@gmail.com, test2@gmail.in`;
-
const Subject = `You got a new mail: ${Number}`;
-
const Body = `Dear User,\n\n New mail received:\n\n\ number: ${Number} \n\tName: ${name}\n\tEmail: ${email} \n\nBest regards,\n name`;
-
GmailApp.sendEmail(Recipient,Subject,Body);
答案1
得分: 1
为了在电子邮件中使特定文本加粗,您需要使用 HTML 标记,就像使用 htmlBody
一样:
function myFunction() {
let Number = 11, name = 'Joe', email = 'test@gmail.com';
const Recipient = 'test@gmail.com';
const Subject = 'You got a new mail: ' + Number;
const Body = "Dear User,<br><br> New mail received:<br><br> number: <b>" + Number + "</b><br> Name:" + name + "<br> Email:" + email + "<br><br>Best regards,<br> name "
var contentHTML = "<body><p>" + Body + "</p></body>";
GmailApp.sendEmail(Recipient, Subject, Body, {
htmlBody: contentHTML
});
}
以上代码将使用 <b> </b>
标记使特定文本加粗,但请注意,您必须将 <\n>
和 <\t>
转换为 <br>
和 &emsp;
以便 HTML 可以识别这些标记。
输出:
参考:
bold specific word in email body while sending it through googlescript
How view 'tab' (tab) sign in HTML document?
英文:
In order to bold
specific texts in the email, you need to use HTML tags by using htmlBody
like this:
function myFunction() {
let Number = 11, name = 'Joe', email = `test@gmail.com`;
const Recipient = `test@gmail.com`;
const Subject = `You got a new mail: ${Number}`;
const Body = "Dear User,<br><br> New mail received:<br><br> number: <b>" + Number + "</b><br>&emsp;Name:" + name + "<br>&emsp;Email:" + email + "<br><br>Best regards,<br> name "
var contentHTML = "<body><p>" + Body + "</p></body>";
GmailApp.sendEmail(Recipient, Subject, Body, {
htmlBody: contentHTML
});
}
the code above will bold specific texts by using the <b> </b>
tags and please note that you have to convert <\n>
and <\t>
to <br>
and &emsp;
so that the HTML can recognize these tags.
Output:
Reference:
bold specific word in email body while sending it through googlescript
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论