I am sure you have a blank character before the "To" keyword in your code. Let's remove it. Your data before you encode it to base64 encoding must to look like this:
From: xxx@xxx.com
To: xxx@xxx.com
Subject: Mail Subject
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
Test body
Best regards,