Exemple #1
0
    def send_reminder(self,gid=None,action=None):
        guest = m.Guest.get(gid)

        with file('/home/robby/coding/mostsplendiferous/smtp_creds.txt','r') as fh:
            username, password = fh.read().strip().split()

        if not guest:
            add_flash('Guest Not Found!')
            return redirect('/guest_list')

        if not guest.email_address:
            add_flash('No email address')
            return redirect('/guest',guest.id)

        # must be admin
        if not is_admin():
            add_flash('Must be admin')
            return redirect('/guest',gid)

        try:
            mail = Mail(
                server=MAIL_SERVER,
                username=username,
                password=password,
                smtp_port=587,
                sender=MAIL_SENDER,
                to=guest.email_address,
                subject=MAIL_SUBJECT,
                template_path=MAIL_TEMPLATE_PATH,
                use_templating=True,
                type='mako',
                replacement_dict={
                    'name':guest.name,
                    'party_size':guest.party_size,
                    'guests':guest.guests_coming,
                    'link': LINK_TEMPLATE % (guest.id,
                                             get_guest_token(guest))
                }
            )

            mail.send()
            guest.email_sent = True
            add_flash('email sent to %s' % ', '.join(mail.to))
            m.session.commit()
        except Exception, ex:
            raise
            add_flash('email failed')
def send_mail():
    mailed = []
    for data in get_data():
        lookup = {'name':('%s %s' % (data.get('first_name',''),
                                     data.get('last_name',''))).strip(),
                  'party_size':data.get('party_size',1) or 1,
                  'guests':data.get('guests',0) or 0 }
        guest = m.Guest.get_by(name=lookup.get('name'))
        if not guest:
            raise Exception('no guest: %s' % lookup)
        link = '%s/%s/%s' % (LINK_BASE,guest.id,get_guest_token(guest))
        lookup['link'] = link
        mail = Mail(server=SERVER,
                    sender=SENDER,
                    to=data.get('email_address'),
                    template_path=TEMPLATE_PATH,
                    use_templating=True,
                    replacement_dict=lookup)
        r = mail.send()
        mailed.append(r)
    return mailed