You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Apps Script自动回复内容换行优化问题咨询

Google Apps Script 自动回复邮件换行设置方案

核心解决方案

你当前使用的是纯文本格式发送邮件,只需要在正文字符串中插入转义换行符\n即可实现换行,两段之间需要空一行的话插入两个\n,就能匹配你需要的分段效果。

修改后完整代码

function autoReplier() {
  var labelObj = GmailApp.getUserLabelByName('autoreply');
  var gmailThreads;
  var messages;
  var sender;

  for (var gg = 0; gg < labelObj.getUnreadCount(); gg++) {
    gmailThreads = labelObj.getThreads()[gg];
    messages = gmailThreads.getMessages();
    for (var ii = 0; ii < messages.length; ii++) {

      if (messages[ii].isUnread()) {
        msg = messages[ii].getPlainBody();
        sender = messages[ii].getFrom();
        // 正文拆分三段,段间用\n\n实现空行分隔
        var replyContent = "AUTOMATIC RESPONSE: Hello, Please note, I respond and can only see your messages when I am on the clock. If I am off, I will not respond.\n\nMy schedule is Sunday, Monday, Wednesday-Friday from 8am-5pm.\n\nPlease remember that you should be seeing your Coach or Team Lead for assistance. If you need assistance with any of the following, click on the links:"
        MailApp.sendEmail(sender, "Auto Reply", replyContent);
        messages[ii].markRead();
        messages[ii].moveToTrash();
      }
    }
  }
}

可选扩展:富文本HTML格式发送

如果后续需要添加加粗、可点击链接等富文本效果,可以选择HTML格式发送邮件,写法示例如下:

// HTML格式正文,用<p>标签实现分段
var htmlReply = `
<p>AUTOMATIC RESPONSE: Hello, Please note, I respond and can only see your messages when I am on the clock. If I am off, I will not respond.</p>
<p>My schedule is Sunday, Monday, Wednesday-Friday from 8am-5pm.</p>
<p>Please remember that you should be seeing your Coach or Team Lead for assistance. If you need assistance with any of the following, click on the links:</p>
`
// 调用sendEmail时传入htmlBody参数
MailApp.sendEmail({
  to: sender,
  subject: "Auto Reply",
  body: replyContent, // 备用纯文本内容,兼容不支持HTML的邮件客户端
  htmlBody: htmlReply
});

内容的提问来源于stack exchange,提问作者Jonathan Vazquez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 12:24:04