public function testSendHTML()
 {
     // Set custom $project - used in email headers
     global $project;
     $oldProject = $project;
     $project = 'emailtest';
     Injector::inst()->registerService(new EmailTest_Mailer(), 'SilverStripe\\Control\\Email\\Mailer');
     $email = new Email('*****@*****.**', '*****@*****.**', 'Test send plain', 'Testing Email->send()', null, '*****@*****.**', '*****@*****.**');
     $email->attachFile(__DIR__ . '/fixtures/attachment.txt', null, 'text/plain');
     $email->addCustomHeader('foo', 'bar');
     $sent = $email->send(123);
     // Restore old project name after sending
     $project = $oldProject;
     $this->assertEquals('*****@*****.**', $sent['to']);
     $this->assertEquals('*****@*****.**', $sent['from']);
     $this->assertEquals('Test send plain', $sent['subject']);
     $this->assertContains('Testing Email->send()', $sent['content']);
     $this->assertNull($sent['plaincontent']);
     $this->assertEquals(array(0 => array('contents' => 'Hello, I\'m a text document.', 'filename' => 'attachment.txt', 'mimetype' => 'text/plain')), $sent['files']);
     $this->assertEquals(array('foo' => 'bar', 'X-SilverStripeMessageID' => 'emailtest.123', 'X-SilverStripeSite' => 'emailtest', 'Cc' => '*****@*****.**', 'Bcc' => '*****@*****.**'), $sent['customheaders']);
 }