I have a web app where authorized users can log in to edit a schedule. In order to remind the users mentioned in the schedule on a weekly base, a mailer running inside of cron is needed. marrow.mailer is a very handy framework to help achieve this goal.
First, I retrieve all the calendar for this week from the database:
now = datetime.now() nextweek = now + timedelta(days=7) cal = ( session.query(model.Calendar) .filter(between(model.Calendar.fake_date, now, nextweek)) ).first()
Then, setup the mailer via marrow.mailer
# start the mailer daemon. I use postfix as my email agent so here I use # localhost as host mailer = Mailer(dict( transport = dict( use = "smtp", host = "localhost"), manager = dict())) mailer.start() message = Message(author="Foo Bar <foo@bar.org>", to=cal.email, cc=["woot@bar.org", "bar@bar.org"], bcc="zoo@bar.org") message.subject = subject message.plain = body mailer.send(message) mailer.stop()