lastError; } public function isConfiguredForOwner(string $ownerPublicId): bool { if ($this->platformEmail->isConfigured()) { return true; } return $this->credentials->forOwner($ownerPublicId)->hasValidBird(); } /** @deprecated Use isConfiguredForOwner() */ public function isConfigured(): bool { return $this->platformEmail->isConfigured(); } public function send( string $ownerPublicId, string $to, string $subject, string $html, ?string $text = null, ?string $replyToEmail = null, ?string $replyToName = null, ): bool { $this->lastError = null; if ($this->platformEmail->isConfigured()) { $sent = $this->platformEmail->send($ownerPublicId, $to, $subject, $html, $text); if ($sent) { return true; } // Suite unavailable (mailbox, allowance) — try Bird power-user path next. $suiteError = $this->platformEmail->lastError(); if ($this->tryCustomerBird($ownerPublicId, $to, $subject, $html, $text)) { return true; } $this->lastError = $suiteError ?: $this->lastError; return false; } return $this->tryCustomerBird($ownerPublicId, $to, $subject, $html, $text); } private function tryCustomerBird( string $ownerPublicId, string $to, string $subject, string $html, ?string $text, ): bool { $credential = $this->credentials->forOwner($ownerPublicId); if (! $credential->hasValidBird()) { $this->lastError ??= 'Connect a Ladill mailbox in Account → Messaging, or connect Ladill Bird in Integrations.'; return false; } $apiKey = $credential->birdApiKey(); if (! $apiKey) { $this->lastError = 'Bird credentials could not be decrypted. Reconnect Bird in Integrations.'; return false; } $sent = $this->customerEmail->send( $apiKey, (string) $credential->bird_from_email, $credential->bird_from_name, $to, $subject, $html, $text, ); if (! $sent) { $this->lastError = $this->customerEmail->lastError() ?: 'The email could not be sent.'; return false; } return true; } }