自动电子邮件脚本中的文本格式 [英] Format text in auto email script

查看:117
本文介绍了自动电子邮件脚本中的文本格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下脚本通过与Google表单同步的电子表格发送自动确认。
$ b

  function formSubmitReply(e){
var userEmail = e.values [2] ;
MailApp.sendEmail(userEmail,
Thanks for Volunteering,
Hello \\\
\\\
+
Thanks you \\\
\\\
+
祝你有美好的一天,
{name:ABC});

\\\
将文本带到下一行。但是,它们都是左对齐的。有什么我可以添加使它正确对齐?像 \r
谢谢

解决方案

电子邮件的文本正文不支持格式。您可以嵌入选项卡( \ t )或空格以尝试将文本推送到右侧;但你怎么知道接收者的显示器有多宽?

如果你想控制你的电子邮件的表示,你需要使用 htmlBody 选项<< p>中,通过嵌入式CSS样式来影响基本格式。 ; div> 标记,并将css属性/值对放置在样式属性中。例如,这将产生右对齐的文本(继续,运行它并看到):

< div> 标记中加入我们所选样式的电子邮件正文的文本版本,将换行符替换为html < br> 标签。当我们发送这封电子邮件时,包括文本和html版本;支持html的电子邮件客户端的收件人将看到右对齐的html版本,其他人将看到纯文本。

  function formSubmitReply(e){
var userEmail = e.values [2];
var text =Hello \\\
\\\
+
Thanks you \\\
\\\
+
祝您有个美好的一天\\\
\\\
;
var html =< div style ='text-align:right'>
+ text.replace(/ \\ / g,< br>)//用换行符替换换行符
+< / div>
MailApp.sendEmail(userEmail,
Thanks for Volunteering,
text,
{name:ABC
htmlBody:html});
}


I use the following script to send auto confirmations from a spreadsheet which is synced with a google form.

function formSubmitReply(e) {
  var userEmail = e.values[2];
  MailApp.sendEmail(userEmail,
                    "Thanks for Volunteering",
                     " Hello\n\n"+
                     "Thanks you\n\n"+
                     "Have a great day\n\n",
                     {name:"ABC"});
                             }​

The \n takes the text to the next line. However, it's all left aligned. Is there anything I can add to make it right aligned? something like \r? Thanks

The text body of an email supports no formatting. You could embed tabs (\t) or spaces to try to push the text to the right; but how would you know how wide the recipient's display is?

If you want to control the presentation of your email, you need to use the htmlBody option described here.

You can affect basic formatting with embedded css styles, by wrapping the text of the email in <div> tags, and placing css property / value pairs in a style attribute. For example, this would produce right-aligned text (go ahead, "run" it and see):

<div style='text-align:right'>
  This is the text <br> that we want to have <br> right-aligned.
</div>

This example wraps the text version of the email body in <div> tags with our selected style, replacing the newline characters to html <br> tags. When we send this email, both the text and html versions are included; recipients with email clients that support html will see the right-aligned html version, others will see the plain text.

function formSubmitReply(e) {
  var userEmail = e.values[2];
  var text = "Hello\n\n"+
             "Thanks you\n\n"+
             "Have a great day\n\n";
  var html = "<div style='text-align:right'>"
           + text.replace(/\\n/g,"<br>")   // Replace newlines with breaks
           + "</div>"
  MailApp.sendEmail(userEmail,
                    "Thanks for Volunteering",
                    text,
                    { name: "ABC"
                      htmlBody: html });
}​

这篇关于自动电子邮件脚本中的文本格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆