Template Mail Version 2

This add-on is a complete rewrite of regular "TMail" class. It adds a lot of simplicity and is much more compact than TMail at the same time it offers the following features:

Basic Usage

Sends simple message with the same text used for both HTML and PlainText

$mail=$this->add('TMail2'); $mail->set('Quick Brown Fox'); $mail->set('subject','Test Email'); $mail->send('to@example.com','from@example.com');

Sets different HTML and Text, also specifies "from" through argument list. Arguments are set as an array, not individually. Also demonstrates that email address may contain full name of the user.

$mail=$this->add('TMail2'); $mail->setHTML('Click here'); $mail->setText('Click Here: http://yahoo.com/'); $mail->set(array( 'subject'=>'Test Email', 'from'=>'John Smith ' )); $mail->send('Rob Williams ');

Will load file from templates/mail/welcome.mail and use it's content as a template for HTML and Text. Does not explicitly specify "from" so $config['tmail']['from'] will be used.

$mail=$this->add('TMail2'); $mail->setTemplate('welcome'); $mail->send('to@example.com');

Shows how you can add new part types. The template will be loaded from templates/mail/mymail.mail by cloning <?mypart?>

class TMail_Part_MyPart extends TMail_Part { ... function defaultTemplate(){ return array('mymail','mypart'); } } $mail=$this->add('TMail2'); $mail->addPart('MyPart'); $mail->send('to@example.com');

Demonstrates how same object can be reused several times to produce emails

$mail=$this->add('TMail2'); $mail->setTemplate('welcome'); foreach($emails as $to){ $mail->send($to); }

Log email into database instead of sending it

$mail=$this->add('TMail2'); $mail->setTemplate('welcome'); $mail->addTransport('DBStore')->setModel('MailLog'); $mail->addTransport('Fallback'); // use default sending method $mail->send($to);

Discard email. Won't send it.

$mail=$this->add('TMail2'); $mail->setTemplate('welcome'); $mail->addTransport('Discard'); $mail->send($to);

Add your own condition. On successful condition check will use SES transport to send over Amazon's Simple Email Service

class TMail_Transport_CheckUser extends TMail_Transport { function init(){ parent::init(); if(!$this->api->getUser()->acceptsMail()) $this->breakHook(true); } } $mail=$this->add('TMail2'); $mail->setTemplate('welcome'); $mail->addTransport('CheckUser'); $mail->addTransport('SES'); $mail->send($to);

Sending file

$file=$this->add('Model_Filestore_File')->loadData($file_id); $mail=$this->add('TMail2'); $mail->setTemplate('welcome'); $mail->addPart('Attachment')->setModel($file); $mail->send($to);

Sending files in multiple emails with same template

$file=$this->add('Model_Filestore_File'); $ids=$file->loadData(array('id')); $mail=$this->add('TMail2'); $mail->setTemplate('welcome'); foreach($ids as $row){ $file->loadData($row['id']); $m = clone $mail; $mail->addPart('Attachment')->setModel($file); $mail->send($to); }