问题描述
我有一个Google表格,其中包含一些我已提取到电子邮件正文中的数据(即下面所示代码中的消息行).但是,我想插入一个以 studentName
开头的新段落,以及另一个以 sessionName
开头的新段落.尝试过 \ r \ n
和< br/>
,但都无法正常工作.为了清楚起见,我希望最终的电子邮件看起来像这样:
I have a Google Sheet containing some data that I've pulled into the body of an email (i.e., the message line in the code shown below). However, I want to insert a new paragraph beginning with studentName
and another new paragraph beginning with sessionName
. Tried \r\n
and <br/>
but can't get either to work. To be clear, I want the final email to look like this:
初级高尔夫诊所注册收据
Junior Golf Clinic Registration Receipt
身体:
这确认您的注册.您的信用卡已被扣款$ 0.00.
This confirms your registration. Your credit card has been charged$0.00.
学生姓名:John Doe
Student Name: John Doe
会话:5月-会话1
function SendEmail() {
// Fetch the email address
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("B2");
var studentRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("C2");
var studentName = studentRange.getValues();
var sessionRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("D2");
var sessionName = sessionRange.getValues();
var emailAddress = emailRange.getValues();
var ChgAmt = Browser.inputBox("Charge Amount");
// Send Alert Email.
var subject = 'Junior Golf Clinic Registration Receipt';
var message = 'This confirms your registration. Your credit card has been charged '+ ChgAmt + <br/> + studentName + sessionName ; // Second column
MailApp.sendEmail(emailAddress, subject, message);
}
推荐答案
- 您要使用Google Apps脚本.
- 您要将换行符添加到电子邮件的文本正文中.
- 您可以通过一个请求检索
B2:D2
的值.这样,可以降低处理成本. - 为了将换行符添加到文本正文中,可以使用
\ n
作为换行符.您也可以使用\ r \ n
.- 我看不到有关
Tried \ r \ n的脚本,但是都无法正常工作.
.所以我直接修改了您的脚本.
- You can retrieve the values of
B2:D2
by one request. By this, the process cost will be able to be reduced. - In order to add the line break to the text body, you can use
\n
as the line break. You can also use\r\n
.- I coudln't see the script about
Tried \r\n and but can't get either to work.
. So I directly modified your script.
当以上几点反映到您的脚本中时,它如下所示.请认为这只是几个答案之一.
When above points are reflected to your script, it becomes as follows. Please think of this as just one of several answers.
function SendEmail() { // Fetch the email address var values = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange("B2:D2").getValues()[0]; var emailAddress = values[0]; var studentName = values[1]; var sessionName = values[2]; var ChgAmt = Browser.inputBox("Charge Amount"); var lineBreak = '\n'; // or \r\n // Send Alert Email. var subject = 'Junior Golf Clinic Registration Receipt'; var message = 'This confirms your registration. Your credit card has been charged ' + ChgAmt + lineBreak + 'Student Name: ' + studentName + lineBreak + 'Session(s): ' + sessionName; MailApp.sendEmail(emailAddress, subject, message); }
参考:
- sendEmail(收件人,主题,身体)
如果我误解了你的问题,而这不是你想要的结果,我深表歉意.我想对其进行修改.
If I misunderstood your question and this was not the result you want, I apologize. And I would like to modify it.
这篇关于在电子邮件正文中开始新的段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- I coudln't see the script about
- 我看不到有关
从您的问题中,我可以像上面那样理解.如果我的理解是正确的,那么该修改如何?
From your question, I could understand like above. If my understanding is correct, how about this modification?