gmail = $gmail; } public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) { /* For some reason the Injected Mail class carries cached tokens, so we need to reinit the Mail class*/ $this->gmail = null; $this->gmail = new Mail; /*We should nest the token in the message and then discard it as needed*/ $token = $message->getHeaders()->get('GmailToken')->getValue(); $message->getHeaders()->remove('GmailToken'); $this->beforeSendPerformed($message); $this->gmail->using($token); $this->gmail->to($message->getTo()); $this->gmail->from($message->getFrom()); $this->gmail->subject($message->getSubject()); $this->gmail->message($message->getBody()); $this->gmail->cc($message->getCc()); if(is_array($message->getBcc())) $this->gmail->bcc(array_keys($message->getBcc())); foreach ($message->getChildren() as $child) { if($child->getContentType() != 'text/plain') { $this->gmail->attach(TempFile::filePath($child->getBody(), $child->getHeaders()->get('Content-Type')->getParameter('name') )); } } /** * Google is very strict with their * sending limits, if we hit 429s, sleep and * retry again later. */ try{ $this->gmail->send(); } catch(\Google\Service\Exception $e) { nlog("gmail exception"); nlog($e->getErrors()); sleep(5); $this->gmail->send(); } $this->sendPerformed($message); return $this->numberOfRecipients($message); } }