Exemple #1
0
def publish(request):
    menuQuery = DBSession.query(Menu).filter(Menu.id==request.matchdict['menu_id'])
    menu = menuQuery.one()
    #only send the email if it hasn't been sent yet
    if not menu.sent:
        mailer = get_mailer(request)
        json_data = open(MAIL_SECRETS)
        data = json.load(json_data)
        json_data.close()

        message = Message(subject=get_menu_name(menu),
                          sender=data["sender"],
                          recipients=[data["recipient"]],
                          body=get_menu_desc(menu, False))
        #print 'sending email to %r' % data["recipient"]
        mailer.send_immediately(message, fail_silently=False)
        menuQuery.update({"sent":True}, synchronize_session=False)
    return json.dumps("Sent")
Exemple #2
0
                        desc = desc + '</div>'
                    if len(allergen_string):
                        desc = desc + "<div style='display: block; font-size:11px; text-align:center'>"
                        desc = desc + '(' + allergen_string + ')'
                        desc = desc + '</div>'
                    desc = desc + '</div><br>\n'
        desc = desc + '<br>\n'

    json_data = open(MAIL_SECRETS)
    data = json.load(json_data)
    json_data.close()
    msg = MIMEMultipart()

    msg['From'] = data["sender"]
    msg['To'] = data["recipient"]
    msg['Subject'] = get_menu_name(menu).decode('utf8')
    html_part1 = """
<html>
  <head></head>
  <body>
  <style>
  * {font-family: Opensans, helvetica, sans-serif;
       font-size: 15px;
  }
</style>
<div style="display:block; font-size:17;text-align:center">
    Today Tuckshop is serving:
</div><br>
     """
    html_part2 ="""
<div style="display:block; font-size:15; text-align:center">