使用Google Apps腳本,如何在變量中設置換行符以發送郵件?消息中的換行符
Q
消息中的換行符
7
A
回答
2
我通常使用表中我的郵箱,但我認爲應該<br />
工作
6
4
發送電子郵件的HTML部分時,您應該使用<br>
標記。
下面是關於如何撰寫相同電子郵件正文的示例,但格式不同的HTML &純文本。 (不是最好的代碼,但希望它說明了這一點)
function onFormSubmit(e) {
var subject = "Subject";
// Collect user data
var name = e.values[0];
var email = e.values[1]; // Where user enters his/her email address
// Generate content - Replace this with what you're composing
var content = [];
content.push("Hi " + name);
content.push("Thanks for submitting the survey!___LINE_BREAK___");
content.push("Survey Team");
// Combine content into a single string
var preFormatContent = content.join('___LINE_BREAK___');
// Replace text with \n for plain text
var plainTextContent = preFormatContent.replace('___LINE_BREAK___', '\n');
// Replace text with <br /> for HTML
var htmlContent = preFormatContent.replace('___LINE_BREAK___', '<br />');
MailApp.sendEmail(email ,
subject,
plainTextContent ,
{
name: "Survey Team",
html: htmlContent
});
}
+0
替換隻搜索第一個實例,雖然有點麻煩,但我的解決方案是preFormatContent.split('___ LINE_BREAK ___')。join('\ n'); – Hovo
2
換行中msgBox
:
Browser.msgBox('line 1 \\\n line 2');
請注意,你需要逃跑「\ n」額外的反斜線。
相關問題
- 1. 插入換行符的IRC消息
- 2. 確認消息字符串中的換行符介紹
- 3. 獲取回覆消息中的換行符
- 4. assertText在Selenium IDE中有換行符的消息
- 5. 傳遞換行符(或<Br />)中的ViewData [「消息」]
- 6. 消息包中的多行消息
- 7. Android Studio:如何在git commit消息中添加換行符?
- 8. 如何在Autohotkey消息框文本中插入換行符
- 9. 在shell腳本中向AWS SNS消息添加換行符
- 10. 從Python記錄器消息中剝離換行符和空格
- 11. 如何在git標記消息中包含換行符
- 12. 多個換行符合並在git commit消息中
- 13. BASH - 在消息輸出中包含換行符
- 14. 使用log4net在日誌消息中處理嵌入換行符
- 15. 使用Objective-C在iOS警報消息中添加換行符
- 16. T-SQL將多個行轉換爲短消息文本字符串/消息
- 17. 短信文本消息 - 做換行符爲字符?
- 18. 消息轉換
- 19. xmlstarlet - 消除換行符
- 20. Visual Studio在斷點打印消息(tracepoint)中插入製表符/換行符?
- 21. 在Mirth連接中生成的HL7消息中添加換行符
- 22. 換行符在SQL Server中消失
- 23. 如何擺脫Checkstyle消息'文件不以換行符結束'。
- 24. 更新UIAlertView消息動態和換行符問題
- 25. 在android中的消息和字符串之間的轉換?
- 26. RabbitMQ消息交換
- 27. 如何在爲Android共享提供的消息中獲得換行符
- 28. 使用python的optparse時在幫助消息中顯示換行符
- 29. 亞馬遜SQS消息中的消息字符編碼問題
- 30. 在c中的消息隊列中進行類型轉換
或
取決於預期的行爲。 – Alexis
_line break_是** BR ** http://www.w3.org/TR/html401/struct/text.html#h-9.3.2.1 – Edo