Question

I am using System.Net.Mail.SmtpClient to send e-mails through a remote SMTP server. When I'm looking at the headers of the sent message, I see that the message gets 2.5 hits from X-Spam. How can I prevent base64 encoding of the From field, and how to get rid of the NULL_IN_BODY hit? Even though it's not marked as spam, I want it to be perfect. I'm unable to find any information regarding this issue (if it really is an issue at all).

MIME-Version: 1.0
From: Myself <no-reply@myself.com>
To: me@myself.com
Date: 25 Mar 2011 15:20:23 +0100
Subject: Test subject
Content-Type: text/plain; charset=us-ascii
X-Spam-Status: No, hits=0.5 required=5.0
X-Spam-Report: 0.5 hits, 5.0 required;
    * -0.5 ALL_TRUSTED            Passed through trusted hosts only via SMTP
    *  1.0 NULL_IN_BODY           FULL: Message has NUL (ASCII 0) byte in message
X-Virus-Scanned: by moam (http://www.moam.net/)
X-Moam-Version: 0.95
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by mx02.example.com id p2PEKKNs014451

Hello, sshow!
Below is your login information

Username: sshow
Password: a8sJdfl

Sent from http://me.myself.com

Edit: I managed to remove the warning for FROM_EXCESS_BASE64, which was the most important one, by removing all encoding for the field. I had previously manually set Encoding.UTF8 for the field.

By removing all control characters from body string, it no longer raises the warning. However, this also removes the line-breaks.

foreach (char c in body)
{
    stringBuilder.Append(Char.IsControl(c) ? ' ' : c);
}

Edit: When removing all control-chars except line-breaks, the warning returns!

foreach (char c in body)
{
    stringBuilder.Append(Char.IsControl(c) && c != '\r' && c != '\n' ? ' ' : c);
}
Was it helpful?

Solution

Without seeing the body of the email or the source code, it's not possible to say for sure, but I would assume the following are true:

  • You have base64 encoded the From header, even though it was not necessary to do so. SpamAssassin considers this a likely attempt to obfuscate something: http://wiki.apache.org/spamassassin/Rules/FROM_EXCESS_BASE64
  • You have binary data (specifically a null byte) in the body of your email. This can happen for example if you dump UTF-16 (UTF-32) encoded text into the body of the email, since ordinary English characters would be represented as two (four) bytes each, one (three) of which is null.

If that does not solve the issue, please post your full code and a hex dump of the whole message.

UPDATE:

Char.IsControl removes CR and LF characters as well ('\r' and '\n'). Change your code to not remove them, e.g.:

Char.IsControl(c) && c != '\r' && c != '\n' ? ' ' : c
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top