Changeset 15023
- Timestamp:
- 01/28/09 14:29:57 (4 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/seSwiftMailerPlugin/lib/GMail.class.php
r15003 r15023 1 1 <?php 2 2 3 class GMail extends seSwift3 class GMail extends SmtpMail 4 4 { 5 5 public function __construct($subject,$sender=null,$pass=null) 6 6 { 7 parent::__construct($subject,$sender,array('pass'=>$pass)); 7 if(!$pass&&!sfConfig::get('app_mail_pass',false)) 8 { 9 throw new Exception('Need to give the password!'); 10 } 11 parent::__construct($subject,'smtp.gmail.com',$sender,$pass,465,true); 12 //__construct($subject,$sender,array('pass'=>$pass,'server'=>'smtp.gmail.com','port'=>,'secure'=>true)); 8 13 } 9 14 10 p rotected function getConnection($subject,$sender,$options)15 public function massMail(Array $mailTos) 11 16 { 12 $connection = new Swift_Connection_SMTP('smtp.gmail.com', 465, Swift_Connection_SMTP::ENC_SSL); 13 if(!$sender) 17 if(count($mailTos)>50) 14 18 { 15 $sender=sfConfig::get('app_gmail_user'); 16 $pass=sfConfig::get('app_gmail_pass'); 19 throw new Exception("The Gmail Smtp server doesn't support more than 50 mails in one batch."); 17 20 } 18 elseif(!isset($options['pass'])||!$options['pass']) 21 parent::massMail($mailTos); 22 } 23 24 public function mail($tos,$ccs,$bccs) 25 { 26 if((count($tos)+count($ccs)+count($bccs))>50) 19 27 { 20 throw new Exception( 'Need to give the password');28 throw new Exception("The Gmail Smtp server doesn't support more than 50 mails in one batch."); 21 29 } 22 $connection->setUsername($sender); 23 $connection->setPassword($options['pass']); 24 25 return $connection; 30 parent::mail($tos,$ccs,$bccs); 26 31 } 27 32 } plugins/seSwiftMailerPlugin/lib/seSwift.class.php
r15004 r15023 10 10 $attachments=array(); 11 11 12 public function __construct($subject,$sender=null,Array $options=array()) 12 abstract protected function getConnection($subject,$sender,$options); 13 14 public function __construct($subject,$sender,Array $options=array()) 13 15 { 14 16 $this->subject=$subject; 15 17 $this->sender=$sender; 16 18 $connection=$this->getConnection($subject,$sender,$options); 19 //var_dump($connection); 17 20 parent::__construct($connection); 18 21 } 19 22 20 abstract protected function getConnection($subject,$sender,$options); 23 public function mail($tos,$ccs,$bccs) 24 { 25 $this->doSend(self::getRecipientList($tos,$ccs,$bccs)); 26 } 27 28 public function sendTo() 29 { 30 $tos=func_get_args(); 31 $this->mail($tos,array(),array()); 32 } 33 34 public function doSend(Swift_RecipientList $recipient) 35 { 36 $message=$this->getMessage(); 37 38 $this->send($message, $recipient, $this->sender); 39 } 40 41 public function massMail(Array $mailTos) 42 { 43 $message=$this->getMessage(); 44 $recipients=self::getRecipientList($mailTos,array(),array()); 45 $this->batchSend($message, $recipients, $this->sender); 46 } 47 48 public function addAttachment($file) 49 { 50 $this->message=false; 51 $this->attachments[]=$file; 52 } 53 54 public function setBodyHtmlFromPartial($templateName, $vars) 55 { 56 $this->setBodyHtml(sfAction::getPartial($templateName, $vars)); 57 } 58 59 public function setBodyTxtFromPartial($templateName, $vars) 60 { 61 $this->setBodyTxt(sfAction::getPartial($templateName, $vars)); 62 } 63 64 public function setBodyHtml($body) 65 { 66 $this->message=false; 67 $this->bodyHtml=$body; 68 } 69 70 public function setBodyTxt($body) 71 { 72 $this->message=false; 73 $this->bodyTxt=$body; 74 } 21 75 22 76 protected function parseImages($body,$message) … … 24 78 $dom = new DOMDocument; 25 79 $dom->loadHTML($body); 26 if (!$dom) { 27 //echo 'Error while parsing the document'; 28 var_dump('Error while parsing the document'); 29 exit; 80 if(!$dom) 81 { 82 throw new Exception('Cannot parse code!'); 30 83 } 31 84 $sx=simplexml_import_dom($dom); … … 35 88 foreach($images as $image) 36 89 { 37 $imagePath= '/asd'.(String)$image->attributes()->src;90 $imagePath=(String)$image->attributes()->src; 38 91 while(!file_exists(sfConfig::get('sf_web_dir').$imagePath)) 39 92 { … … 50 103 } 51 104 52 53 public function massMail(Array $mailTos)54 {55 foreach($mailTos as $mailTo)56 {57 $this->send($mailTo);58 }59 }60 61 105 /** 62 106 * … … 121 165 } 122 166 123 public function mail($tos,$ccs,$bccs)124 {125 $this->doSend(self::getRecipientList($tos,$ccs,$bccs));126 }127 128 public function sendTo()129 {130 $tos=func_get_args();131 $this->mail($tos,array(),array());132 }133 134 public function doSend(Swift_RecipientList $recipient)135 {136 $message=$this->getMessage();137 138 $this->send($message, $recipient, $this->sender);139 }140 141 167 protected function getMessage() 142 168 { … … 188 214 return $message->attach(new Swift_Message_Image(new Swift_File($image))); 189 215 } 190 191 public function addAttachment($file)192 {193 $this->message=false;194 $this->attachments[]=$file;195 }196 197 public function setBodyHtmlFromPartial($templateName, $vars)198 {199 $this->setBodyHtml(sfAction::getPartial($templateName, $vars));200 }201 202 public function setBodyTxtFromPartial($templateName, $vars)203 {204 $this->setBodyTxt(sfAction::getPartial($templateName, $vars));205 }206 207 public function setBodyHtml($body)208 {209 $this->message=false;210 $this->bodyHtml=$body;211 }212 213 public function setBodyTxt($body)214 {215 $this->message=false;216 $this->bodyTxt=$body;217 }218 216 }