Google Apps Script,发送带有粗体内容的电子邮件

huangapple go评论91阅读模式
英文:

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>&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
  });
}

以上代码将使用 <b> </b> 标记使特定文本加粗,但请注意,您必须将 &lt;\n&gt;&lt;\t&gt; 转换为 &lt;br&gt;&amp;emsp; 以便 HTML 可以识别这些标记。

输出:

Google Apps Script,发送带有粗体内容的电子邮件

参考:

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 = &#39;Joe&#39;, email = `test@gmail.com`;

  const Recipient = `test@gmail.com`;

  const Subject = `You got a new mail: ${Number}`;

  const Body = &quot;Dear User,&lt;br&gt;&lt;br&gt; New mail received:&lt;br&gt;&lt;br&gt; number: &lt;b&gt;&quot; + Number + &quot;&lt;/b&gt;&lt;br&gt;&amp;emsp;Name:&quot; + name + &quot;&lt;br&gt;&amp;emsp;Email:&quot; + email + &quot;&lt;br&gt;&lt;br&gt;Best    regards,&lt;br&gt; name &quot;
  var contentHTML = &quot;&lt;body&gt;&lt;p&gt;&quot; + Body + &quot;&lt;/p&gt;&lt;/body&gt;&quot;;

  GmailApp.sendEmail(Recipient, Subject, Body, {
    htmlBody: contentHTML
  });

}

the code above will bold specific texts by using the &lt;b&gt; &lt;/b&gt; tags and please note that you have to convert &lt;\n&gt; and &lt;\t&gt; to &lt;br&gt; and &amp;emsp; so that the HTML can recognize these tags.

Output:

Google Apps Script,发送带有粗体内容的电子邮件

Reference:

bold specific word in email body while sending it through googlescript

How view '\t' (tab) sign in HTML document?

huangapple
  • 本文由 发表于 2023年4月11日 14:15:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75982880.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定