格式化Sieve脚本以将MIME包含在HTML中的正确方法是什么?

时间:2019-06-25 12:53:08

标签: html-email dovecot sieve-language

我正在尝试使用Dovecot Sieve在服务器上实现自动响应器。我设法用简单的html生成了筛选脚本,但是可以,但是当尝试实现更复杂的html时,我收到语法错误。

如何制定筛分脚本以允许使用更复杂的html?如何解决语法错误?

:mime参数应该用引号引起来,我猜这就是中断的地方。但是我尝试搜索有关如何正确编码脚本的指南,但找不到任何内容。

例如,此代码有效...

require ["fileinto","vacation"];

vacation 
:subject "subject here" 
:mime "MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html><html><head></head><body>12345</body></html>";

但这不是...

require ["fileinto","vacation"];

vacation 
:subject "subject here" 
:mime "MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">

<head>
  <meta charset="utf-8"> <!-- utf-8 works for most cases -->
  <meta name="viewport" content="width=device-width"> <!-- Forcing initial-scale shouldn't be necessary -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- Use the latest (edge) version of IE rendering engine -->
  <meta name="x-apple-disable-message-reformatting"> <!-- Disable auto-scale in iOS 10 Mail entirely -->
</head>

<body width="100%" style="background: #ffffff; margin: 0; mso-line-height-rule: exactly;">
  <center style="width: 100%; background: #ffffff; text-align: left;">

    <div style="max-width: 680px; margin: auto;" class="email-container">

      <!-- Email Header : BEGIN -->
      <table role="presentation" cellspacing="0" cellpadding="0" border="0" align="center" width="100%" style="max-width: 680px;">
        <tr>
          <td style="padding: 40px 20px; text-align: center">
            <img src="logo.png" width="300" height="47" alt="alt_text" border="0" style="height: auto; background: #ffffff; font-family: sans-serif; font-size: 15px; line-height: 140%; color: #555555;">
          </td>
        </tr>
      </table>
      <!-- Email Header : END -->

      <!-- Email Body : BEGIN -->
      <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" style="max-width: 680px;" class="email-container">

        <!-- 1 Column Text : BEGIN -->
        <tr>
          <td bgcolor="#ffffff">
            <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
              <tr>
                <td style="padding: 20px; font-family: sans-serif; font-size: 15px; line-height: 140%; color: #555555;">
                  test
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <!-- 1 Column Text : END -->

      </table>
      <!-- Email Body : END -->
    </div>


    </td>
    </tr>
    </table>
  </center>
</body>

</html>";

错误消息是

Unable to parse script: script errors:
line 16: syntax error, unexpected $undefined, expecting ';'
line 68: unexpected end of file in string

1 个答案:

答案 0 :(得分:2)

您将想用placing a backslash before them在HTML中的双引号转义:

require ["fileinto","vacation"];

vacation
:subject "subject here"
:mime "MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>

<html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\">

<head>
  <meta charset=\"utf-8\"> <!-- utf-8 works for most cases -->
  <meta name=\"viewport\" content=\"width=device-width\"> <!-- Forcing initial-scale shouldn't be necessary -->
  <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"> <!-- Use the latest (edge) version of IE rendering engine -->
  <meta name=\"x-apple-disable-message-reformatting\"> <!-- Disable auto-scale in iOS 10 Mail entirely -->
</head>

<body width=\"100%\" style=\"background: #ffffff; margin: 0; mso-line-height-rule: exactly;\">
  <center style=\"width: 100%; background: #ffffff; text-align: left;\">

    <div style=\"max-width: 680px; margin: auto;\" class=\"email-container\">

      <!-- Email Header : BEGIN -->
      <table role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" align=\"center\" width=\"100%\" style=\"max-width: 680px;\">
        <tr>
          <td style=\"padding: 40px 20px; text-align: center\">
            <img src=\"logo.png\" width=\"300\" height=\"47\" alt=\"alt_text\" border=\"0\" style=\"height: auto; background: #ffffff; font-family: sans-serif; font-size: 15px; line-height: 140%; color: #555555;\">
          </td>
        </tr>
      </table>
      <!-- Email Header : END -->

      <!-- Email Body : BEGIN -->
      <table role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\" style=\"max-width: 680px;\" class=\"email-container\">

        <!-- 1 Column Text : BEGIN -->
        <tr>
          <td bgcolor=\"#ffffff\">
            <table role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">
              <tr>
                <td style=\"padding: 20px; font-family: sans-serif; font-size: 15px; line-height: 140%; color: #555555;\">
                  test
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <!-- 1 Column Text : END -->

      </table>
      <!-- Email Body : END -->
    </div>


    </td>
    </tr>
    </table>
  </center>
</body>

</html>";