Ejemplo n.º 1
0
def send_update_mails(ticket, ticket_update):
    """
    Sends email to all users who commented or created ticket
    """
    assigned_sent = check_assigned_to(ticket)

    recipients = set([])

    if not ticket.mailbox_hash:

        ticket.mailbox_hash = hashlib.sha224("ticket-%s"%ticket.id).hexdigest()
        ticket.save()

    if ticket.assigned_to:
        if ticket.assigned_to.email:
            recipients.add(ticket.assigned_to.email)

    if not assigned_sent and ticket.assigned_to:
        if ticket.assigned_to.email in recipients:
            recipients.remove(ticket.assigned_to.email)

    for recipient in ticket.get_recipients():
        if recipient.email:
            recipients.add(recipient.email)

    if Core.current_user().email:
        if Core.current_user().email in recipients:
            recipients.remove(Core.current_user().email)

    if ticket_update.public and ticket_update.comment:
        _send_to_clients(ticket, ticket_update)

    msg = _create_msg(ticket, ticket_update)
    send_mail(_("Ticket update"), msg, "support+"+ticket.mailbox_hash+"@focustime.no", recipients)
Ejemplo n.º 2
0
def client_management(request, id):
    offer = Offer.objects.get(id=id)

    if request.method == "POST":
        form = AddClientForm(request.POST)

        if form.is_valid():
            email_address = request.POST['email']
            client, created = ClientUser.objects.get_or_create(email=email_address)

            client.offers.add(offer)
            client.save()

            password_text = "Bruk din epostadresse og passord fra tidligere. Du kan også be om å få tilsendt nytt."
            if created:
                password = client.generate_password()
                client.set_password(password)
                client.save()
                password_text = "Bruk din epostadresse og passord: %s" % (password)

            message = """
            Hei. Du har fått tilsendt et nytt tilbud. Logg inn på %s for å se detaljer.

            %s

            """ % (settings.CLIENT_LOGIN_SITE, password_text)
            send_mail(_("New offer"), message, settings.NO_REPLY_EMAIL, [email_address])

    else:
        form = AddClientForm()

    return render(request, "offers/client_management.html", {'offer': offer, 'form': form})
Ejemplo n.º 3
0
def client_management(request, id):
    ticket = Ticket.objects.get(id=id)

    if request.method == "POST":
        form = AddClientForm(request.POST)

        if form.is_valid():
            email_address = request.POST['email']
            client, created = ClientUser.objects.get_or_create(email=email_address)

            client.tickets.add(ticket)
            client.save() # not needed?

            if created:
                password = client.generate_password()
                client.set_password(password)
                client.save()
                password_text = "Bruk din epostadresse og passord: %s" % password

            else:
                password_text = "Bruk din epostadresse og passord fra tidligere. Du kan også be om å få tilsendt nytt."

            message = """
            Hei. Du har fått tilgang til å følge en sak hos oss. Logg inn på %s for å se detaljer.

            %s

            """ % (settings.CLIENT_LOGIN_SITE, password_text)
            send_mail(_("New ticket"), message, settings.NO_REPLY_EMAIL, [email_address])

    else:
        form = AddClientForm()

    return render(request, "tickets/client_management.html", {'ticket': ticket, 'form': form})
Ejemplo n.º 4
0
def send_assigned_mail(user, ticket, assigned=True):
    if not user.email:
        return
    url = settings.SITE_URL + reverse("ticket_view", kwargs={'id': ticket.id})

    if assigned:
        msg = (" %s %s \n %s: %s \n\n") % (_("You have been assigned to the ticket"),ticket.title, _("Link"), url)
    else:
        msg = (" %s %s \n %s: %s \n\n") % (_("You have been unassigned to the ticket"),ticket.title, _("Link"), url)

    msg += _("Description") + "\n" + ticket.description

    send_mail(ticket.title, msg, settings.NO_REPLY_EMAIL, [user.email])
Ejemplo n.º 5
0
 def handle(self, *args, **options):
     users = self.get_diary_users()
     diary_needed = self.get_diary_needed(users=users)
     diary_existing = self.get_diary_existing()
     diary_missing = self.get_diary_missing(needed=diary_needed,
                                            existing=diary_existing)
     email_configs = self.get_email_configs(missing=diary_missing)
     for config in email_configs:
         subject, body, to, cc = config['subject'], config['body'], config[
             'to'], config['cc']
         if not options['debug']:
             send_mail(subject=subject, body=body, to=to, cc=cc)
         log = (f'to:\n{to}\n'
                f'cc:\n{cc}\n'
                f'subject:\n{subject}\n'
                f'body:\n{body}')
         logger.info(log)
Ejemplo n.º 6
0
    def handle(self, *apps, **options):
        try:
            csv_file = "https://www.dnbnor.no/portalfront/datafiles/miscellaneous/csv/kursliste.csv"

            val_file = csv.reader(urllib.urlopen((csv_file)))
            values = [val.iso for val in Currency.objects.all()]

            for i in val_file:
                iso = i[2]
                if i[9]:
                    value = Decimal(i[9])
                    if i[1]:
                        innok = Decimal(i[1])
                        if iso in values:
                            currency = Currency.objects.get(iso=iso)
                            currency.value = value / innok
                            currency.save()
        except Exception, e:
            send_mail("Problems during currency update", "%s" % e, "*****@*****.**", ["*****@*****.**"],
                      fail_silently=False)
Ejemplo n.º 7
0
def stripe_view(f_request):
    stripe_error_subject = "Stripe Export Error"
    if f_request.method == 'POST':
        body = f_request.json
        event = _treat_request(body) if body else 1

        if event[0] == 0:
            send_mail(body=("Miss event name or user_id %s" % str(event[1])),
                      subject=stripe_error_subject,
                      force_mail=True)
            abort(404)
        elif event[0] == 1:
            send_mail(body="Miss body in request",
                      subject=stripe_error_subject)
            abort(404)
        else:
            send_event = {"service": "STRIPE", "event": event[1]}
            segment.track(send_event)
            response = {"response": "Well Done!"}
            response = jsonify(response)
            return response
    elif f_request.method == 'GET':
        send_mail(body="GET request instead of POST",
                  subject=stripe_error_subject)
        abort(404)
Ejemplo n.º 8
0
def appsflyer_view(f_request, platform):
    appsflyer_error_subject = "Appsflyer Export Error"
    if f_request.method == 'POST':
        body = f_request.json
        event = _treat_request(body, platform) if body else 1

        if event[0] == 0:
            send_mail(body=("Miss event name or user_id %s" % str(event[1])), subject=appsflyer_error_subject)
            abort(404)
        elif event[0] == 1:
            send_mail(body="Miss body in request", subject=appsflyer_error_subject)
            abort(404)
        elif event[0] == 2:
            send_event = {
                "service": "APPSFLYER",
                "event": event[1]
            }
            if event[1]["event"] in [
                "asker_demand_published_front",
                "asker_prepaid_booked_front",
                "application_installed"
            ]:
                segment.track(send_event)

            response = {
                "response": "Well Done!"
            }
            response = jsonify(response)
            return response
    elif f_request.method == 'GET':
        send_mail(body="GET request instead of POST", subject=appsflyer_error_subject)
        abort(404)
Ejemplo n.º 9
0
def new_password(request):
    if request.is_ajax() and request.method == 'POST':
        email = request.POST['email']
        ret = {'error': False}
        print ret
        try:
            client = ClientUser.objects.get(email=email)
            pwd = ClientUser.generate_password()
            client.set_password(pwd)
            client.save()
            send_mail(_('New Password'),
                      _('Your new password is: ') + '%s' % pwd,
                      settings.NO_REPLY_EMAIL, [email],
                      fail_silently=False)
            ret['text'] = _('New password sent')
        except ClientUser.DoesNotExist:
            ret['error'] = True
            ret['text'] = _('Email not found')
        return HttpResponse(simplejson.dumps(ret),
                            mimetype='application/javascript')
    else:
        return HttpResponse(status=404)
Ejemplo n.º 10
0
def client_management(request, id):
    ticket = Ticket.objects.get(id=id)

    if request.method == "POST":
        form = AddClientForm(request.POST)

        if form.is_valid():
            email_address = request.POST['email']
            client, created = ClientUser.objects.get_or_create(
                email=email_address)

            client.tickets.add(ticket)
            client.save()  # not needed?

            if created:
                password = client.generate_password()
                client.set_password(password)
                client.save()
                password_text = "Bruk din epostadresse og passord: %s" % password

            else:
                password_text = "Bruk din epostadresse og passord fra tidligere. Du kan også be om å få tilsendt nytt."

            message = """
            Hei. Du har fått tilgang til å følge en sak hos oss. Logg inn på %s for å se detaljer.

            %s

            """ % (settings.CLIENT_LOGIN_SITE, password_text)
            send_mail(_("New ticket"), message, settings.NO_REPLY_EMAIL,
                      [email_address])

    else:
        form = AddClientForm()

    return render(request, "tickets/client_management.html", {
        'ticket': ticket,
        'form': form
    })
Ejemplo n.º 11
0
    def handle(self, *apps, **options):
        try:
            csv_file = "https://www.dnbnor.no/portalfront/datafiles/miscellaneous/csv/kursliste.csv"

            val_file = csv.reader(urllib.urlopen((csv_file)))
            values = [val.iso for val in Currency.objects.all()]

            for i in val_file:
                iso = i[2]
                if i[9]:
                    value = Decimal(i[9])
                    if i[1]:
                        innok = Decimal(i[1])
                        if iso in values:
                            currency = Currency.objects.get(iso=iso)
                            currency.value = value / innok
                            currency.save()
        except Exception, e:
            send_mail("Problems during currency update",
                      "%s" % e,
                      "*****@*****.**", ["*****@*****.**"],
                      fail_silently=False)
Ejemplo n.º 12
0
def send_by_email(application, msg, handler):
    send_account = '*****@*****.**'
    send_password = '******'
    send_smtp_address = 'smtp.exmail.qq.com'
    send_smtp_port = 465
    rev_list = [handler['address']]
    mail_title = '消息中心'
    mail_text = msg
    mail_file_list = ['/home/carhj/npm-debug.log']

    yield send_mail(application, send_account, send_password,
                    send_smtp_address, send_smtp_port, rev_list, mail_title,
                    mail_text, mail_file_list)
Ejemplo n.º 13
0
def client_management(request, id):
    offer = Offer.objects.get(id=id)

    if request.method == "POST":
        form = AddClientForm(request.POST)

        if form.is_valid():
            email_address = request.POST['email']
            client, created = ClientUser.objects.get_or_create(
                email=email_address)

            client.offers.add(offer)
            client.save()

            password_text = "Bruk din epostadresse og passord fra tidligere. Du kan også be om å få tilsendt nytt."
            if created:
                password = client.generate_password()
                client.set_password(password)
                client.save()
                password_text = "Bruk din epostadresse og passord: %s" % (
                    password)

            message = """
            Hei. Du har fått tilsendt et nytt tilbud. Logg inn på %s for å se detaljer.

            %s

            """ % (settings.CLIENT_LOGIN_SITE, password_text)
            send_mail(_("New offer"), message, settings.NO_REPLY_EMAIL,
                      [email_address])

    else:
        form = AddClientForm()

    return render(request, "offers/client_management.html", {
        'offer': offer,
        'form': form
    })
Ejemplo n.º 14
0
Archivo: user.py Proyecto: frecar/focus
def generate_new_password_for_user(user):
    import string
    import random

    vowels = ['a', 'e', 'i', 'o', 'u']
    consonants = [a for a in string.ascii_lowercase if a not in vowels]
    ret = ''
    slen = 8
    for i in range(slen):
        if i % 2 == 0:
            randid = random.randint(0, 20) #number of consonants
            ret += consonants[randid]
        else:
            randid = random.randint(0, 4) #number of vowels
            ret += vowels[randid]
    ret += "%s" % random.randint(20, 99)
    send_mail(_("New password"), (_("Your username is: %s" % user.username) + _("\nYour password is: ") + '%s' % ret),
              settings.NO_REPLY_EMAIL,
        [user.email], fail_silently=False)

    user.set_password("%s" % ret)

    user.save()
    return ret
Ejemplo n.º 15
0
def mailer(title, machine, password, username, user_email):
    send_mail(title, machine, password, username, user_email)
Ejemplo n.º 16
0
    def get_new_emails(self):
        import poplib
        import string
        import email

        for company in Company.objects.all():

            if company.admin_group and company.email_host and company.email_password and company.email_username:

                print company.email_host

                Core.set_test_user(company.admin_group.members.all()[0])

                M = poplib.POP3(company.email_host)
                M.user(company.email_username)
                M.pass_(company.email_password)

                numMessages = len(M.list()[1])

                print numMessages

                for i in range(numMessages):
                    print "=" * 40
                    msg = M.retr(i + 1)
                    M.dele(i + 1)
                    str = string.join(msg[1], "\n")
                    str = re.sub(r"\r(?!=\n)", "\r\n", str)

                    mail = email.message_from_string((str))

                    email_address = ""

                    for text, encoding in decode_header(mail["From"]):
                        if encoding:
                            email_address += text.decode(encoding)
                        else:
                            email_address += text

                    address_start = email_address.find("<") + 1
                    address_end = email_address.find(">")
                    email_address = email_address[address_start:address_end]

                    subject = mail["Subject"]

                    k = 3
                    for index in [m.start() for m in re.finditer("\_" + "\?=", subject)]:
                        subject = subject[: index + k] + " " + subject[index + k :]
                        k += 1

                    decoded = decode_header(subject)

                    s = ""

                    for text, encoding in decoded:
                        if encoding:
                            s += text.decode(encoding)
                        else:
                            s += text

                    subject = s

                    if mail.is_multipart():
                        content = mail.get_payload(0).get_payload()
                    else:
                        content = mail.get_payload()

                    ticketClient, created = ClientUser.objects.get_or_create(email=email_address)
                    if created:
                        password = ticketClient.generate_password()
                        ticketClient.set_password(password)

                        message = """Hei. Takk for din henvendelse. \n Vi har opprettet en sak hos oss.
                        Du kan følge progresjon og komme med kommenterer ved å logge inn på %s

                        Bruk din epostadresse og passordet: %s

                                    """ % (
                            settings.CLIENT_LOGIN_SITE,
                            password,
                        )
                    else:
                        message = """Hei. Takk for din henvendelse. \n Vi har opprettet en sak hos oss.
                        Du kan følge progresjon og komme med kommenterer ved å logge inn på %s

                                    """ % (
                            settings.CLIENT_LOGIN_SITE
                        )

                    send_mail("Din henvendelse er registrert", message, settings.NO_REPLY_EMAIL, [email_address])

                    ticket = Ticket()
                    ticket.title = subject

                    encoding = "utf-8"
                    if "text/plain" in mail["Content-Type"]:
                        encoding = "latin1"

                    ticket.description = content.decode(encoding).strip()

                    ticket.description = ticket.description.replace("=F8", u"ø")
                    ticket.description = ticket.description.replace("=D8", u"Ø")
                    ticket.description = ticket.description.replace("=E6", u"æ")
                    ticket.description = ticket.description.replace("=C6", u"Æ")
                    ticket.description = ticket.description.replace("=E5", u"å")
                    ticket.description = ticket.description.replace("=C5", u"Å")
                    ticket.description = ticket.description.replace("=20", u"\n")

                    ticket.priority = TicketPriority.objects.all()[0]
                    ticket.status = TicketStatus.objects.all()[0]
                    ticket.type = TicketType.objects.all()[0]

                    ticket.client_user = ticketClient
                    print company
                    ticket.company = company
                    ticket.save()

                    ticketClient.tickets.add(ticket)
                    ticketClient.save()

                M.quit()
Ejemplo n.º 17
0
def _send_to_clients(ticket, ticket_update):
    recipients = [client.email for client in ticket.clients.all()]
    msg = _create_client_msg(ticket, ticket_update)
    send_mail(_("Ticket update"), msg, settings.NO_REPLY_EMAIL, recipients)
Ejemplo n.º 18
0
    def get_new_emails(self):
        import poplib
        import string
        import email

        for company in Company.objects.all():

            if company.admin_group and company.email_host and company.email_password and company.email_username:

                print company.email_host

                Core.set_test_user(company.admin_group.members.all()[0])

                M = poplib.POP3(company.email_host)
                M.user(company.email_username)
                M.pass_(company.email_password)

                numMessages = len(M.list()[1])

                print numMessages

                for i in range(numMessages):
                    print "=" * 40
                    msg = M.retr(i + 1)
                    M.dele(i+1)
                    str = string.join(msg[1], "\n")
                    str = re.sub(r'\r(?!=\n)', '\r\n', str)

                    mail = email.message_from_string((str))

                    email_address = ""

                    for text, encoding in decode_header(mail["From"]):
                        if encoding:
                            email_address += text.decode(encoding)
                        else:
                            email_address += text

                    address_start = email_address.find("<")+1
                    address_end = email_address.find(">")
                    email_address = email_address[address_start:address_end]

                    subject = mail["Subject"]

                    k = 3
                    for index in [m.start() for m in re.finditer('\_'+'\?=',subject)]:
                        subject = subject[:index+k] + " " + subject[index+k:]
                        k+=1

                    decoded = decode_header(subject)

                    s = ""

                    for text, encoding in decoded:
                        if encoding:
                            s+= text.decode(encoding)
                        else:
                            s+= text

                    subject = (s)

                    if mail.is_multipart():
                        content = mail.get_payload(0).get_payload()
                    else:
                        content = mail.get_payload()


                    ticketClient, created = ClientUser.objects.get_or_create(email=email_address)
                    if created:
                        password = ticketClient.generate_password()
                        ticketClient.set_password(password)

                        message = """Hei. Takk for din henvendelse. \n Vi har opprettet en sak hos oss.
                        Du kan følge progresjon og komme med kommenterer ved å logge inn på %s

                        Bruk din epostadresse og passordet: %s

                                    """ % (settings.CLIENT_LOGIN_SITE, password)
                    else:
                        message = """Hei. Takk for din henvendelse. \n Vi har opprettet en sak hos oss.
                        Du kan følge progresjon og komme med kommenterer ved å logge inn på %s

                                    """ % (settings.CLIENT_LOGIN_SITE)

                    send_mail("Din henvendelse er registrert", message, settings.NO_REPLY_EMAIL, [email_address])

                    ticket = Ticket()
                    ticket.title = subject

                    encoding = "utf-8"
                    if 'text/plain' in mail["Content-Type"]:
                        encoding = "latin1"

                    ticket.description = content.decode(encoding).strip()

                    ticket.description = ticket.description.replace("=F8",u"ø")
                    ticket.description = ticket.description.replace("=D8",u"Ø")
                    ticket.description = ticket.description.replace("=E6",u"æ")
                    ticket.description = ticket.description.replace("=C6",u"Æ")
                    ticket.description = ticket.description.replace("=E5",u"å")
                    ticket.description = ticket.description.replace("=C5",u"Å")
                    ticket.description = ticket.description.replace("=20",u"\n")

                    ticket.priority = TicketPriority.objects.all()[0]
                    ticket.status = TicketStatus.objects.all()[0]
                    ticket.type = TicketType.objects.all()[0]

                    ticket.client_user = ticketClient
                    print company
                    ticket.company = company
                    ticket.save()

                    ticketClient.tickets.add(ticket)
                    ticketClient.save()

                M.quit()