html-emaildovecotsieve-language

What is the correct way to format a Sieve script to include MIME with HTML?


I am trying to implement autoresponders on a server using Dovecot Sieve. I have managed to produce sieve scripts with simple html which works, however, when trying to implement more complex html I am receiving syntax errors.

How can I formulate the sieve script to allow for more complex html? How can I fix syntax errors?

The :mime parameter is supposed to be surrounded by quotes, and I guess thats where it's breaking. But I have tried searching for guidance on how to correctly encode the script and I cannot find any.

For instance, this code works...

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>";

But this does not...

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>";

The error messages are

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

Solution

  • You will want to escape the double-quotes in the HTML by placing a backslash before them:

    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>";