Development

Changeset 15023

You must first sign up to be able to contribute.

Changeset 15023

Show
Ignore:
Timestamp:
01/28/09 14:29:57 (4 years ago)
Author:
broesch
Message:

added functionality for local mail and general smtp servers, refactoring

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/seSwiftMailerPlugin/lib/GMail.class.php

    r15003 r15023  
    11<?php 
    22 
    3 class GMail extends seSwift 
     3class GMail extends SmtpMail 
    44{ 
    55  public function __construct($subject,$sender=null,$pass=null) 
    66  { 
    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)); 
    813  } 
    914   
    10   protected function getConnection($subject,$sender,$options) 
     15  public function massMail(Array $mailTos) 
    1116  { 
    12     $connection = new Swift_Connection_SMTP('smtp.gmail.com', 465, Swift_Connection_SMTP::ENC_SSL); 
    13     if(!$sender) 
     17    if(count($mailTos)>50) 
    1418    { 
    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."); 
    1720    } 
    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) 
    1927    { 
    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."); 
    2129    } 
    22     $connection->setUsername($sender); 
    23     $connection->setPassword($options['pass']); 
    24      
    25     return $connection; 
     30    parent::mail($tos,$ccs,$bccs); 
    2631  } 
    2732} 
  • plugins/seSwiftMailerPlugin/lib/seSwift.class.php

    r15004 r15023  
    1010    $attachments=array(); 
    1111   
    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()) 
    1315  { 
    1416    $this->subject=$subject; 
    1517    $this->sender=$sender; 
    1618    $connection=$this->getConnection($subject,$sender,$options); 
     19    //var_dump($connection); 
    1720    parent::__construct($connection); 
    1821  } 
    1922   
    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  } 
    2175   
    2276  protected function parseImages($body,$message) 
     
    2478    $dom = new DOMDocument; 
    2579    $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!'); 
    3083    } 
    3184    $sx=simplexml_import_dom($dom); 
     
    3588      foreach($images as $image) 
    3689      { 
    37         $imagePath='/asd'.(String)$image->attributes()->src; 
     90        $imagePath=(String)$image->attributes()->src; 
    3891        while(!file_exists(sfConfig::get('sf_web_dir').$imagePath)) 
    3992        { 
     
    50103  } 
    51104   
    52    
    53   public function massMail(Array $mailTos) 
    54   { 
    55     foreach($mailTos as $mailTo) 
    56     { 
    57       $this->send($mailTo); 
    58     } 
    59   } 
    60    
    61105  /** 
    62106   * 
     
    121165  } 
    122166   
    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    
    141167  protected function getMessage() 
    142168  { 
     
    188214    return $message->attach(new Swift_Message_Image(new Swift_File($image))); 
    189215  } 
    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   } 
    218216}