cornernote / yii-email-module

Email system with templates and email queuing.

Home Page:https://cornernote.github.io/yii-email-module/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not able to send email using yiic

kavitama opened this issue · comments

Hi @cornernote ,

I am having an problem with sending an email using the email module.
It is correctly installed since it can be used by the your account module but if i try to follow instructions on how to set it up to send emails from a "cron" console based yii app I fail.

I always get the following:

# /var/www/html/reports/protected/yiic cron hostNotifications
Error: Call to a member function renderPartial() on null in /var/www/html/reports/protected/vendor/cornernote/yii-email-module/email/components/EEmailManager.php:277
Stack trace:
#0 /var/www/html/reports/protected/vendor/cornernote/yii-email-module/email/components/EEmailManager.php(263): EEmailManager->buildTemplateMessage_php('host_notificati...', Array, 'layout_fancy')
#1 /var/www/html/reports/protected/components/CustomEmailManager.php(16): EEmailManager->buildTemplateMessage('host_notificati...', Array, 'layout_fancy')
#2 /var/www/html/reports/protected/commands/CronCommand.php(109): CustomEmailManager->emailHostNotifications('25')
#3 [internal function]: CronCommand->actionHostNotifications()
#4 /var/www/f/yii-1.1.18/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(CronCommand), Array)
#5 /var/www/f/yii-1.1.18/framework/console/CConsoleCommandRunner.php(71): CConsoleCommand->run(Array)
#6 /var/www/f/yii-1.1.18/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run(Array)
#7 /var/www/f/yii-1.1.18/framework/base/CApplication.php(185): CConsoleApplication->processRequest()
#8 /var/www/f/yii-1.1.18/framework/yiic.php(33): CApplication->run()
#9 /var/www/html/reports/protected/yiic.php(7): require_once('/var/www/f/yii-...')
#10 /var/www/html/reports/protected/yiic(4): require_once('/var/www/html/r...')

In the "cron" I call the email send function this way:
Yii::app()->consoleEmailManager->emailHostNotifications($rHost->id);

In the console.php file I have the component configured this way:

    'components' => array(
        'consoleEmailManager' => array(
            // path to the EEmailManager class
            'class' => 'application.components.CustomEmailManager',
            // Default from email address.
            'fromEmail' => 'noreply@nutpile.com',
            // Default from name. If unset the application name is used.
            'fromName' => 'Nutpile Networks',
            // Template type, can be one of: php, db.
            'templateType' => 'php',
            // When templateType=php this is the path to the email views. You may copy the default templates from email/views/emails.
            'templatePath' => 'application.views.emails',
            // List of template parts that will be rendered.
            'templateFields' => array('subject', 'heading', 'message'),
            // The default layout to use for template emails.
            'defaultLayout' => 'layout_fancy',
            // The default transport to use.
            'defaultTransport' => 'smtp',
            // A list of email transport methods
            'transports' => array(
                'mail' => array(
                    'class' => 'Swift_MailTransport',
                ),
                'smtp' => array(
                    // if you use smtp you may need to define the host, port, security and setters
                    'class' => 'Swift_SmtpTransport',
                    'host' => 'localhost',
                    'port' => 25,
                    'security' => null,
                ),
            ),
        ),
    ),

Line 277 of EEmailManager.php is this one:

            $viewParams['contents'] = $controller->renderPartial($this->templatePath . '.' . $template . '.' . $field, $viewParams, true);

Any idea of what could it be?
Am I doing something wrong in the configuration?

Hi @cornernote ,

I have found that the line 275 of EEmailManager.php is empty.
This is the reason why it is not working, it cannot render partial and empty controller.

Question? Why this?

Is it an issue with sending emails using console functions or what?

This line?

https://github.com/cornernote/yii-email-module/blob/master/email/components/EEmailManager.php#L275

To be honest, I only ever used the DB templates. If you get it working please do a PR...

This may be helpful - https://stackoverflow.com/a/7043616/599477

I was using it with DB templates but the result is the same that is why I went back to PHP.
Mainly when it is execute in a cronjob (using the yiic command) it complains about not being able to identify the account, which is tricky since NO account is used.

I can turn it back to DB Templates, but I was having the same issue.

Not sure if it means that with DB templates it should work