I noticed that transactional emails from a Magento shop were often marked as spam. Apache SpamAssasin gives a 2.0 score from the BASE64_LENGTH_79_INF rule.

The rule explanation states:

According to http://en.wikipedia.org/wiki/Base64 , base 64 should only be 76 chars long, so these are out of format.

From the linked Wikipedia article:

MIME does not specify a fixed length for Base64-encoded lines, but it does specify a maximum line length of 76 characters. Additionally it specifies that any extra-alphabetic characters must be ignored by a compliant decoder, although most implementations use a CR/LF newline pair to delimit encoded lines.

So it looks like base64 encoded content is not broken into lines as expected. Did anybody encounter the same? What could cause this bad format?


In Zend Framework,magento/lib/Zend/Mime.php implements a const LINELENGTH = 72; but the constant is overwritten in app/code/core/Zend/Mime.php and set to 200. You can overwrite app/code/core/Zend/Mime.php using Magento's regular mechanisms and change the implementation of the encode method, replacing self::LINELENGTH with a different constant:

public static function encode($str, $encoding, $EOL = self::LINEEND)
    switch ($encoding) {
        case self::ENCODING_BASE64:
           // original: return self::encodeBase64($str, self::LINELENGTH, $EOL);
           return self::encodeBase64($str, 72, $EOL); // hardcoded value, just to emphasize the meaning

            return self::encodeQuotedPrintable($str, self::LINELENGTH, $EOL);

             * @todo 7Bit and 8Bit is currently handled the same way.
            return $str;

/Edit: initially I replaced self::LINELENGTH with Zend_Mime::LINELENGTH; this won't work because the autoloader will always load the Zend_Mime class from Magento core instead of the one from lib/Zend.

| improve this answer | |
  • is there a reason for hardcoding to 72 and not 76 ? – raduparvan Sep 17 '15 at 9:01
  • 1
    The original implementation of Zend_Mime is const LINELENGTH = 72; (see lib/Zend/Mime.php) so I saw no reason not to trust that; probably the difference to 76 is used for line endings. Hardcoding the value instead of using a proper constant was just to show the point. In the real implementation, that value must live in a constant. /Edit: The implementation of Zend_Mime::encodeBase64() uses chunk_split which splits the string in $chunklen then adds $end (see php.net/manual/en/function.chunk-split.php) – Adi Sep 17 '15 at 9:22

How is your mail server (SMTP) set up? Is your SPF record correct?

There are various reasons why the mail might me marked as spam, the content is only a part of it.

More info here: https://blog.amasty.com/5-steps-for-no-spam-e-mails-in-magento/

| improve this answer | |
  • I am looking for this specific reason, which is related to the content only. But the linked article contains a useful bit of information: "Magento by default uses 200 for quote-printable line length. This can be changed by overriding Zend_Mime class." - thanks! – Fabian Schmengler Sep 14 '15 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.