Silverstripe 4.1.0
Method Swift_Message::__toString() must not throw an exception
I get this error message:
Method Swift_Message::__toString() must not throw an exception, caught Swift_IoException: Unable to open file for reading [/assets/foo/a84ca8c15f/foo.pdf]
when i attach an file to an email.
This is the code that generates the email
private function sendMailToCustomer()
{
$session = $this->getSession();
$session = $session->get('TempSessionOrder');
$customerEmail = $session->InvoiceEmailAddress;
$email = new EmailCustomerProofshop();
$email->setTo("$customerEmail");
$email->setSubject('Ihre Foo-Bestellung bei Foo - ' . $session->Bestellnummer);
$email->setData(['Order' => $session]);
$email->addAttachment(File::get()->filter(['name' => $session->ID . '.pdf'])->first()->getURL());
$email->send();
}
I wrote an file extension to set permissions:
class FileExtension extends DataExtension
{
public function canCreate($member = null, $context = [])
{
return true;
}
public function canPublish($member = null)
{
return true;
}
public function canView($member = null)
{
return true;
}
public function canEdit($member = null)
{
return true;
}
}
The file that i want to attach does exist.