0

I have a little flask app which allows users to send emails to each other. Right now I send these emails directly, but since this takes usually a second or two I would like to avoid letting the user wait and instead I would like to put the email in a stack and empty this stack every 15min with a cronjob or something like that. I did some google search, but could not find any solution for that. Does anybody know of some flask package to use for that or do I have to implement this myself? I am using flask_mail but this package does not seem to provide any functionality like that... thanks carl

carl
  • 4,216
  • 9
  • 55
  • 103
  • cronjob is enough if it only a little app, what I do (but with web2py) is calling my a python script which is basically my send mail function... One thing you may consider is that depending on how you send you mail, some IAP limit the number of emails you can send to prevent spam, so in your python script you may use time.sleep(t) and you just have to iterate over a list of email to be send... You can put them in a table and clear them out as you process the list and limit the number of mail to be send to let your script/cronjob complete... – Richard Sep 04 '15 at 00:53
  • 1
    I seconds celery ... its not exactly what you describe ... but I think it is the correct answer ... – Joran Beasley Sep 04 '15 at 01:02
  • ok thanks guys... I will look into this... My first impression is that celery is a very big package and there should be an easier solution...? – carl Sep 04 '15 at 06:24

1 Answers1

0

If anybody is interested, here is my solution. I just created a new email_stack model in my models.py (I am using sql-alchemy).

class email_stack(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    message = db.Column(db.String(10000))
    recipient = db.Column(db.String(1000))
    subject = db.Column(db.String(1000))
    sender = db.Column(db.String(1000))

    def __repr__(self):
        return '<email_stack %r>' % (self.id) 

now I run a cronjob every 15min which looks at the email_stack and if there are elements in there it just sends them out and removes them from the stack. This works fine for me. I am sure the celery solution suggested by others would do the same, but I think celery is a big product and was a bit too big for just this little problem. cheers carl

carl
  • 4,216
  • 9
  • 55
  • 103