Email class


I want to make an email class (I know how to make the class) but what is the best way to incorporate the class into Yii.

It needs to be available in all the controllers etc.

Start with a component - a CApplicationComponent - like this:

Any reason why you can’t use that extension, by the way?

But, CApplicationComponent is the way to go.

Hmm no real reason why I cannot use the extension.

However I do have some other areas of the application that will require me to make a class that is accessible throughout the applications controllers so could you tell me how to do that?

Also why I am here do you know of any extension that allows to pull emails out of an email inbox into the application?

In my app, I have this small app component:


class Textilizer extends CApplicationComponent


	protected $_textile;

	protected function _getTextile() {

    	if ($this->_textile===null)

            	$this->_textile = new Textile;

    	return $this->_textile;


   public function textilize($content, $parseSmilies = true) {

    	$text = $this->_getTextile()->TextileThis($content);

    	return $text;



I could have thrown in an ‘init’ function, but I chose not to.

In my config I have this:

	'components' => array(

    	'textile' => array(

        	'class' => 'application.components.textile.Textilizer',


Then I can just use it all over the place app, like this:

<?php echo Yii::app()->textile->textilize($project->description); ?>

I am not sure if YiiMail will allow you to fetch emails from a smtp account, but I guess it would. :)

You can use the ext in as component then call it in the controller to access it from anywhere of your application.

To read emails from messages, you need to create the controllers that will fetch the data from the mailbox and then parse them to your needs.

Thanks for your help everyone.