cornernote / yii-email-module

Email system with templates and email queuing.
https://cornernote.github.io/yii-email-module/
Other
20 stars 15 forks source link

yiic emailSpool error in getModule('email') #7

Closed jecourte closed 10 years ago

jecourte commented 10 years ago

I'm getting the following error when trying to send spooled messages via the yiic emailSpool command:

Fatal error: Call to a member function getDbConnection() on a non-object in /home/content/xxx/xxxxxxxx/html/dev/protected/modules/email/components/EmailActiveRecord.php on line 130

This is the line it's stopping on is $email = Yii::app()->getModule('email');

For some reason it can't use the getModule function when running as a console application.

I made sure to set up my aliases like such in my console config:

'aliases'=>array(
    'bootstrap' => dirname(__FILE__).'/../extensions/bootstrap',
    'email' => dirname(__FILE__).'/../modules/email',
),

Is there something that I'm missing? I read one post that aliases to modules didn't work on console apps.

cornernote commented 10 years ago

Hello @jecourte,

Thanks for taking the time to share this issue.

It should work find from yiic. I have several apps running spooled emails this way.

Are you able to share your config/console.php (or whichever yii config file you use for yiic)? Please note to remove any sensitive information first, such as your database credentials.

jecourte commented 10 years ago

I’ve been running in with the Yii-environment plugin, so the console config gets pulled from the main-development config. I don’t have it in front of me right now so I’ll have to email you it later.

Another question that I’m still not understanding is how to render a template into a layout.

In the documentation you have this line for a Layout Subject: {{subject}} - My Application

Then right below it this line: {{content}} - My Application

So do you use {{content}} in all of the subject, heading, message of the Layout? And not use the variables {{subject}} {{heading}} {{message}}?

Also, do the template args just populate the Template and not the Layout?

Do you have an example of a template fully working with a layout?

Here’s what I’m doing now roughly

TEMPLATE subject = hi {{user.name}} heading = {{user.name}}, Welcome to Sportsman Tracker message = Here is my test message

LAYOUT subject = {{content}} - Sportsman Tracker header = {{content}} - Sportsman Tracker message =

{{{content}}}

Any suggestions?

Thanks, Jeff

On Feb 10, 2014, at 6:49 PM, cornernote notifications@github.com wrote:

Hello @jecourte,

Thanks for taking the time to share this issue.

It should work find from yiic. I have several apps running spooled emails this way.

Are you able to share your config/console.php (or whichever yii config file you use for yiic)? Please note to remove any sensitive information first, such as your database credentials.

— Reply to this email directly or view it on GitHub.

cornernote commented 10 years ago

Hey @jecourte,

Do you mean the documentation here? http://cornernote.github.io/yii-email-module/

I couldn't find the parts you mentioned, but there is an explanation in the FAQ (right at the bottom).

So do you use {{content}} in all of the subject, heading, message of the Layout? And not use the variables {{subject}} {{heading}} {{message}}?

Yep, exactly.

Also, do the template args just populate the Template and not the Layout?

I believe they also populate the layout, but it is advised to use {{content}} and not the template vars.

Do you have an example of a template fully working with a layout?

The example in the migrations should be fully working: https://github.com/cornernote/yii-email-module/blob/master/email/migrations/email_template.mysql

Here’s what I’m doing now roughly...

That looks right. What is the result you are getting?

jecourte commented 10 years ago

I just look at the source code and noticed that it uses a plural “contents” and not “content”

Ahhhh there we go…

~Jeff

On Feb 10, 2014, at 10:47 PM, cornernote notifications@github.com wrote:

Hey @jecourte,

Do you mean the documentation here? http://cornernote.github.io/yii-email-module/

I couldn't find the parts you mentioned, but there is an explanation in the FAQ (right at the bottom).

So do you use {{content}} in all of the subject, heading, message of the Layout? And not use the variables {{subject}} {{heading}} {{message}}?

Yep, exactly.

Also, do the template args just populate the Template and not the Layout?

I believe they also populate the layout, but it is advised to use {{content}} and not the template vars.

Do you have an example of a template fully working with a layout?

The example in the migrations should be fully working: https://github.com/cornernote/yii-email-module/blob/master/email/migrations/email_template.mysql

Here’s what I’m doing now roughly...

That looks right. What is the result you are getting?

— Reply to this email directly or view it on GitHub.

cornernote commented 10 years ago

Nice spotting. I rarely refer to the documentation so It was overlooked. I have updated the documentation to be the plural {{contents}}. Thank you!

I'll leave the issue open so we can debug the command line issue.

cornernote commented 10 years ago

I also found the place you noticed with {{subject}} - My Application, and changed it to {{contents}} - My Application. Now it will be easier for others to understand.

jecourte commented 10 years ago

Cool -- Glad I could help.

Nice extension.

Is there an advantage to running the spooled emails from yiic over calling the spool command from a button? My email list is quite large (72K) and I'll be sending emails out weekly.

Thanks again, Jeff

On Mon, Feb 10, 2014 at 11:03 PM, cornernote notifications@github.comwrote:

I also found the place you noticed with {{subject}} - My Application, and changed it to {{contents}} - My Application. Now it will be easier for others to understand.

Reply to this email directly or view it on GitHubhttps://github.com/cornernote/yii-email-module/issues/7#issuecomment-34724768 .

cornernote commented 10 years ago

If it's a command script you can call it via cron without invoking apache.

I use a tool called lockrun which offers script overlap protection, then I set a long loop so that its always trying to send. Emails are then delivered almost in realtime as they are generated.

If you do decide make your cron call apache then make sure you put an IP filter so that only the server you want to run it has access. I would still recommend using lockrun to prevent overlaps.

jecourte commented 10 years ago

Hey I got my email system up and running. I think I got everything running pretty smoothly. One more question though: I'm running a php script via our web interface that add emails to my spool for a newsletter that we send out. The list is 72K users. When I click the button to queue the emails, the script times out at about 50K emails. Is there a better way to add emails to the queue? I have a bunch of options that I select via text boxes and select menus which makes the web interface nice, but is it going to work for queue mass emails? Do you have something that works better?

Thanks, Jeff

On Feb 10, 2014, at 11:44 PM, cornernote notifications@github.com wrote:

If it's a command script you can call it via cron without invoking apache.

I use a tool called lockrun which offers script overlap protection, then I set a long loop so that its always trying to send. Emails are then delivered almost in realtime as they are generated.

If you do decide make your cron call apache then make sure you put an IP filter so that only the server you want to run it has access. I would still recommend using lockrun to prevent overlaps.

— Reply to this email directly or view it on GitHub.

cornernote commented 10 years ago

Hey Jeff,

I have not yet had the opportunity to send to such a large audience with this module, however I have discussed it a little with some other developers.

I believe the main overhead is serializing and compressing the swiftmailer object. If you have ideas to improve the performance of this I'd love to hear them, however I don't think a lot can be done. You could see if it saves time by not running the pack() method on them, and simply serialize the data without gzipping it.

Another solution that I use for load-intensive web stuff is to do it from a ConsoleApplication (eg, yiic). You may create something like GenerateEmailCommand. Inside it would build the emails and push them into the spool, or it could even send the emails directly without spooling them. This would remove the time constraints that are imposed by the WebApplication.

Let me know your thoughts on this, or if you have any ideas to improve performance.

cornernote commented 10 years ago

no activity in 2 months, closing issue. If you still have concerns please reply and I will re-open.