Exemple #1
0
 def send_confirmation(self, member_record):
     member = member_record['details']
     sendmail(create_email(
         frm="*****@*****.**",
         to="%s %s <%s>" % (member['given_names'], member['surname'], member['email']),
         subject="Welcome to Pirate Party Australia!",
         text=self.welcome_email.format(name=member['given_names'].split(" ")[0])
     ))
Exemple #2
0
 def send_email(self, content):
     sendmail(create_email(
         frm=self.config['from'],
         to=self.config['to'],
         subject="Website Update: %s" % self.url,
         text="URL: %s\n\n%s" % (self.url, content.decode())
     ))
     logger.info("[%s] Email sent." % self.url)
    def post(self):
        fields = OrderedDict([
            ("Candidate Details", OrderedDict([
                ("Full Name", "name"),
                ("Phone", "phone"),
                ("Email", "email")
            ])),
            ("Nomination", {"State": "nomination_state"}),
            ("Seconder Details", OrderedDict([
                ("Full Name", "seconder_name"),
                ("Phone", "seconder_phone"),
                ("Email", "seconder_email")
            ])),
            ("Candidate Questions", OrderedDict([
                ("Why do you feel that you are qualified for the position for which you have declared your candidacy?", "q1"),
                ("Why are you seeking the position for which you have declared your candidacy?", "q2"),
                ("What experience/contribution have you made so far to the Pirate movement, and what will you do to advance or better the Party and movement?", "q3"),
                ("Do you agree with the Pirate Party platform and its ideals? What other political movements or parties have you been a part of?", "q4"),
                ("# Disclosure of history", "background")
            ])),
            ("Submission", {"Pledge agreed to?": "pledge"})
        ])

        # Deal with files
        attachments = []
        for file in self.request.files.values():
            attachments.append(create_attachment(file[0]['filename'], file[0]['body']))

        answers = []
        for heading, x in fields.items():
            answers.append("\n# %s" % heading)
            for k, v in x.items():
                if heading == "Candidate Questions":
                    answers.append("%s\n%s\n" % (k, self.get_argument(v, "")))
                elif heading == "Submission":
                    answers.append("%s\n%s\n" % (k, "Yes" if self.get_argument(v, "") == "on" else "No"))
                else:
                    answers.append("%s: %s" % (k, self.get_argument(v, "")))

        name = self.get_argument("name")
        text = "\n".join(answers).strip()
        frm = "%s <%s>" % (name, self.get_argument('email'))

        sendmail(create_email(
            frm=self.application.email_to,
            to=self.application.email_to,
            subject="Preselection Nomination: %s" % name,
            text=text,
            attachments=attachments
        ))

        logging.debug(text)
        self.write(self.application.success_template % text)
Exemple #4
0
    def send_admin_message(self, member_record, reason):
        member = member_record['details']
        msg = "[Audit] Member resigned: %s %s [%s] (%s)" % (member['given_names'],
                member['surname'], member['email'], member['residential_state'])
        id = member_record['_id'].hex

        sendmail(create_email(
                frm='*****@*****.**',
                to='*****@*****.**',
                subject=msg,
                text="%s\n\n%s" % (id, reason)
        ))
        logging.info("%s %s" % (msg, id))
Exemple #5
0
    def send_admin_message(self, member_record):
        member = member_record['details']
        id = member_record['_id'].hex

        msg = self._get_msg(member)

        sendmail(create_email(
                frm='*****@*****.**',
                to='*****@*****.**',
                subject=msg,
                text=id
        ))
        logging.info("%s %s" % (msg, id))
Exemple #6
0
    def send_admin_message(self, member_record):
        member = member_record['details']
        msg = "Payment method selected: %s %s [%s] (%s)" %\
                (member['given_names'], member['surname'],
                 member['email'], member['residential_state'])
        id = member_record['_id'].hex

        sendmail(create_email(
                frm='*****@*****.**',
                to='*****@*****.**',
                subject=msg,
                text="%s\n%s" % (id, member_record['invoices'][0]['payment_method'])
        ))
        logging.info("%s %s" % (msg, id))
        logging.debug(dumps(member_record, indent=2))
Exemple #7
0
    def send_admin_message(self, member_record):
        member = member_record['details']
        msg = "[Audit] Updated member: %s %s [%s] (%s)" % (member['given_names'],
                member['surname'], member['email'], member['residential_state'])
        id = member_record['_id'].hex

        sendmail(create_email(
                frm='*****@*****.**',
                reply_to=member['email'],
                to='*****@*****.**',
                subject=msg,
                text=id
        ))
        logging.info("%s %s" % (msg, id))
        logging.debug(dumps(member_record, indent=2))
Exemple #8
0
    def send_admin_message(self, member_record):
        member = member_record['details']
        msg = "New %s member: %s %s [%s] (%s)" % (member['membership_level'], member['given_names'],
                member['surname'], member['email'], member['residential_state'])
        id = member_record['_id'].hex

        sendmail(create_email(
                frm='*****@*****.**',
                reply_to=member['email'],
                to='*****@*****.**',
                subject=msg,
                text="%s\n%s\n$%s" % (id, member_record['invoices'][0]['payment_method'],
                    member_record['invoices'][0]['items'][0]['price']/100)
        ))
        logging.info("New member: %s %s" % (msg, id))
        logging.debug(dumps(member_record, indent=2))
Exemple #9
0
def create_tokens_and_send_email(slug, dry_run=False, force=False):
    elections = Connection().stopgap.elections

    election = elections.find_one({"slug": slug})
    if election is None:
        raise Exception("There is no election by the name of '%s'" % slug)

    unsent = []
    for o in election['participants']:
        if o['sent'] is not True:
            unsent.append(o['email'])

    total_unsent = len(unsent)
    if not force:
        res = input("Are you sure you want to send %s emails?\n[y/N]>" % total_unsent)
        if res.lower() != "y":
            return

    for n, email in enumerate(unsent):
        sys.stdout.write("[%s/%s] %s... " % (n+1, total_unsent, email))
        token = uuid.uuid4()

        if not dry_run:
            res = safe_modify(elections, {"slug": slug}, {"$push": {"tokens": token}})
            if res is False:
                raise Exception("A token failed to be saved to the server: '%s'" % token.hex)

        mail = create_email(
                frm=election['email']['from'],
                subject=election['email']['subject'],
                to=email,
                text=election['email']['content'].format(
                    slug=slug,
                    token=token.hex
                )
        )

        if not dry_run:
            sendmail(mail)
            res = safe_modify(elections, {"slug": slug, "participants.email": email},
                {"$set": {"participants.$.sent": True}})
            if res is False:
                raise Exception("An email sent flag failed to be set for '%s'" % email)
        print("Sent!")
Exemple #10
0
    def create_and_send_invoice(self, member, invoice):
        if invoice['payment_method'] == "paypal":
            biller_info = self.paypal.create_biller_info(
                member['given_names'],
                member['surname'],
                member['primary_phone'],
                member['residential_address'],
                None,
                member['residential_suburb'],
                member['residential_state'],
                member['residential_postcode']
            )

            response = self.paypal.create_and_send_invoice(
                self.config['email'],
                member['email'],
                self.paypal.get_merchant_info(),
                biller_info,
                self.paypal.create_invoice_item(invoice['items'][0]['item'], str(invoice['items'][0]['price']/100)),
                payment_terms="Net30"
            )

            if response['responseEnvelope']['ack'].startswith("Success"):
                invoice['reference'] = response['invoiceNumber']
                invoice['paypal_id'] = response['invoiceID']
                return invoice
            else:
                return None

        elif invoice['payment_method'] in ("direct_deposit", "cheque"):
            personal = {
              "name": "Pirate Party Australia Incorporated",
              "address": [],
              "contact": {
                "Email": "*****@*****.**",
                "Website": "<a href='http://pirateparty.org.au'>http://pirateparty.org.au</a>"
              },
              "business_number": "99 462 965 754",
              "payment_methods": [
                {
                  "Direct Deposit": [
                    "Name: Pirate Party Australia Incorporated",
                    "BSB: 012084",
                    "Account number: 213142205",
                    "Bank: ANZ"
                  ]
                }, {
                  "Cheque": [
                    "Address:",
                    "Pirate Party Australia",
                    "PO Box 385",
                    "Figtree NSW 2525"
                  ]
                }
              ]
            }


            member_level = "INVALID"
            if member['membership_level'] == "full":
                member_level = "Full Membership"
            elif member['membership_level'] == "associate":
                member_level = "Associate Membership"

            invoice_tmpl = {
                "regarding": member_level,
                "name": "%s %s" % (member['given_names'], member['surname']),
                "reference": invoice['reference'],
                "items": [
                  {
                    "rate_price": invoice['items'][0]['price'],
                    "tax": "0",
                    "description": invoice['items'][0]['item'],
                    "hours_qty": "1"
                  }
                ],
                "already_paid": "0",
                "details": "",
                "address": [
                  member['residential_address'],
                  "%s %s %s" % (member['residential_suburb'],
                      member['residential_state'], member['residential_postcode'])
                ],
                "date": invoice['issued_date'].strftime("%d/%m/%Y"),
                "message": "Thanks for joining Pirate Party Australia!",
                "payment_due": invoice['due_date'].strftime("%d/%m/%Y")
            }

            pdf_data = Invoice(invoice_tmpl, personal).to_pdf()
            try:
                sendmail(create_email(
                    frm="*****@*****.**",
                    to="%s %s <%s>" % (member['given_names'], member['surname'], member['email']),
                    subject="Pirate Party Membership Invoice (%s)" % invoice_tmpl['reference'],
                    text=self.invoice_email.format(name=member['given_names'].split(" ")[0]),
                    attachments=[create_attachment("ppau-invoice.pdf", pdf_data)]
                ))
                return invoice
            except Exception as e:
                logging.error("Failed to send invoice - %s" % e)
            return None
        else:
            raise Exception("How did you even get here?")