views:

213

answers:

2

I have a google app engine code that tries to send a mail with an attachment of size 379KB. The mail has two recipients - one on the "To" list and myself on the "BCC" list. Apparently, GAE is treating this as 2 different mails which makes it an attempt to send mails with attachment size 758KB(379*2) and is resulting in QuotaExceededException as it exceeds the per minute quota of 500 odd KB/minute. While the mail reaches the recipient on the "To" list, the one on the Bcc (myself) is not receiving the mail.

Can task queue service be considered for solution to this problem? will the task queue framework retry transmission of the mail to recipients who did not get the mail whenever QuotaExceededException occurs?

Further, I plan to extend the aforementioned code in such a way that it would send the same mail (with attachment) to several users. This would obvioulsy result in QuotaExceededException if transmission to all recipients is attempted without any time gap. Can Task queue service help me in this case in any way?

+3  A: 

I think that Task Queues would cover this use case nicely. In fact, the example that Google uses in its documentation of Task Queues is one in which emails are sent through them.

Two things to think about:

  1. Google lists Task Queues as an experimental feature that may be subject to change in future releases, so if you are using this for production code, be prepared for your application's behavior to change suddenly and without warning.
  2. You'll need to configure your queue such that it does not process emails faster than they can be sent without violating your quotas. Check out the Queue Concepts section in the documentation.

Finally, have you considered hosting this large attachment as a URL and having the email contain a link to it? That'd make sending the emails much easier, and it'd be kinder to your overall bandwidth consumption, as only the recipients who really wanted it would get it.

Adam Crossland
thanks adamyes..i considered putting in a link..its not an option i can pursue in this particular case
Aadith
Adam, another quick question..to send several mails in succession without facing QuotaException, would it be a good idea to do a Thread.currentThread().sleep(1 min) after each mail transmission?
Aadith
Aadith, you can not use any threading functions in AppEngine; they are not allowed. Also, you'd run up against the limit of 30 seconds per request. The correct way to handle it is to configure the Task Queue to only process a request once per minute. You can find out more about configuring Task Queues here: http://code.google.com/appengine/docs/python/config/queue.html
Adam Crossland
+1  A: 

Almost. The task queue will retry an action until it succeeds, but it will retry the whole task. AFAIK it doesn't know or remember anything about partial success. So if you just do your current action (sending to two recipients) as a task, I suspect that bad things will happen to the recipient in the To: field, as the task keeps sending them an email but failing overall, once a minute, forever...

So, you'll want to use two tasks (on the same queue): one task for each recipient.

Steve Jessop
thanks steve..shall try this
Aadith
I agree with Steve. Each task in the task queue can only send to one recipient; otherwise, you will have the same problem that you have now but worse.
Adam Crossland