Exemple #1
0
def view_mail_thread(request, mail):
    mail = Mail.objects.get(pk=mail)
    mails = _get_mail_list(request)
    start = mail.start_of_thread()
    if not request.user.is_anonymous() \
           and request.method == "POST":
        form = MailForm(request, request.POST, request.FILES)
        if form.is_valid():
            mail = form.save(in_reply_to=start.end_of_thread())
            return redirect(reverse('preview', kwargs={'mail': mail.pk}))
    else:
        if request.user.is_anonymous():
            form = MailForm(request)
        else:
            form = MailForm(request,
                            initial={
                                'mfrom': request.user.email,
                                'mto': start.mto.email,
                                'subject': 'Re: %s' % start.subject
                            })
    if start == mail:
        return locals()
    else:
        return redirect(reverse('mail',
                                kwargs={'mail':start.id})\
                        + "#mail-%d" % mail.id)
Exemple #2
0
def view_mail_thread(request, mail):
    mail = Mail.objects.get(pk=mail)
    mails = _get_mail_list(request)
    start = mail.start_of_thread()
    if not request.user.is_anonymous() \
           and request.method == "POST":
        form = MailForm(request, request.POST, request.FILES)
        if form.is_valid():
            mail = form.save(in_reply_to=start.end_of_thread())
            return redirect(reverse('preview',
                                    kwargs={'mail': mail.pk}))
    else:
        if request.user.is_anonymous():
            form = MailForm(request)
        else:
            form = MailForm(request,
                               initial={'mfrom':request.user.email,
                                        'mto':start.mto.email,
                                        'subject':'Re: %s' % start.subject})
    if start == mail:
        return locals()
    else:
        return redirect(reverse('mail',
                                kwargs={'mail':start.id})\
                        + "#mail-%d" % mail.id)
Exemple #3
0
def contact_us(request):
    if request.method == 'POST':
        form = MailForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            city = form.cleaned_data['city']
            number = form.cleaned_data['number']
            email = form.cleaned_data['email']
            subject = form.cleaned_data['subject']
            feedback = form.cleaned_data['feedback']
            sg = sendgrid.SendGridAPIClient(
                apikey=
                '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'
            )

            from_email = Email('[email protected] ')
            to_email = Email("*****@*****.**")
            subject = subject
            content = Content(
                "text/plain",
                "Following email is from a user who visited Social Bot Web App"
                + "\n\n" + feedback + "\n\nFrom: " + name + "\n\nCity: " +
                city + "\n\nPhone Number: " + number + "\n\nEmail: " + email)
            mail = Mail(from_email, subject, to_email, content)
            response = sg.client.mail.send.post(request_body=mail.get())
            print(response.status_code)
            print(response.body)
            print(response.headers)
            print("mail sent.")
            return HttpResponseRedirect('/feed/')
Exemple #4
0
def home(request):
    context = {}

    if request.method == 'POST':
        form = MailForm(request.POST)
        if form.is_valid():
            emails.save({'_id': form.save_mail().encode('ascii')})
            context['success'] = True

    return render(request, 'base.html', context)
Exemple #5
0
def email_me(request):
    if request.method == 'POST':
        mailForm = MailForm(request.POST)
        if mailForm.is_valid():
            send_mail(mailForm.cleaned_data['subject'],mailForm.cleaned_data['message'],mailForm.cleaned_data['email'],['*****@*****.**'])
            return HttpResponseRedirect('/news/')
        else:
            return render_to_response('mail_me.html',{'mailForm':mailForm}, RequestContext(request))
    else:
        return render_to_response('mail_me.html',{'mailForm':MailForm()}, RequestContext(request))
Exemple #6
0
def userprofile(request):
    (profile, created) = UserProfile.objects.get_or_create(user=request.user)
    form = mailform = None

    if request.method == 'POST':
        if request.POST['submit'] == 'Save':
            form = UserProfileForm(request.user,
                                   request.POST,
                                   instance=profile)
            if form.is_valid():
                form.save()
                messages.add_message(request, messages.INFO,
                                     "User profile saved.")
                return HttpResponseRedirect('.')
        elif request.POST['submit'] == 'Add email':
            mailform = MailForm(request.POST)
            if mailform.is_valid():
                m = UserExtraEmail(user=request.user,
                                   email=mailform.cleaned_data['email'],
                                   confirmed=False,
                                   token=generate_random_token(),
                                   tokensent=datetime.now())
                m.save()
                send_template_mail(
                    settings.NOTIFICATION_FROM, request.user.username, m.email,
                    'Your email address for commitfest.postgresql.org',
                    'extra_email_mail.txt', {
                        'token': m.token,
                        'user': m.user
                    })
                messages.info(
                    request,
                    "A confirmation token has been sent to %s" % m.email)
                return HttpResponseRedirect('.')
        else:
            messages.error(request,
                           "Invalid submit button pressed! Nothing saved.")
            return HttpResponseRedirect('.')

    if not form:
        form = UserProfileForm(request.user, instance=profile)
    if not mailform:
        mailform = MailForm()

    extramails = UserExtraEmail.objects.filter(user=request.user)

    return render_to_response('userprofileform.html', {
        'form': form,
        'extramails': extramails,
        'mailform': mailform,
    },
                              context_instance=RequestContext(request))
Exemple #7
0
def email_me(request):
    if request.method == 'POST':
        mailForm = MailForm(request.POST)
        if mailForm.is_valid():
            send_mail(mailForm.cleaned_data['subject'],
                      mailForm.cleaned_data['message'],
                      mailForm.cleaned_data['email'], ['*****@*****.**'])
            return HttpResponseRedirect('/news/')
        else:
            return render_to_response('mail_me.html', {'mailForm': mailForm},
                                      RequestContext(request))
    else:
        return render_to_response('mail_me.html', {'mailForm': MailForm()},
                                  RequestContext(request))
Exemple #8
0
def write(request):
    mails = _get_mail_list(request)
    footer = get_footer_for_mail()
    if request.method == "POST":
        form = MailForm(request, request.POST, request.FILES)
        if form.is_valid():
            mail = form.save()
            return redirect(reverse('posted',
                                    kwargs={'mail': mail.pk}))
    else:
        if request.user.is_anonymous():
            form = MailForm(request)
        else:
            form = MailForm(request,
                               initial={'mfrom':request.user.email,
                                        'name':request.user.full_name})
    return locals()
Exemple #9
0
def sent_mail(request):
    if request.method == "POST":
        form = MailForm(request.POST)
        if form.is_valid():
            sender_name = form.cleaned_data["sender_name"]
            email = form.cleaned_data["email"]
            letter_text = form.cleaned_data["letter_text"]
            try:
                send_mail("Сообщение от ", letter_text, email, ["*****@*****.**"], fail_silently=False)
                message = "Сообщение отправлено!"
            except:
                message = "Ошибка отправки!!"

            request.session["mail_message"] = message
        else:
            request.session["mail_message"] = "Ошибка формы отправки!"
    return redirect("/")
Exemple #10
0
def write(request):
    mails = _get_mail_list(request)
    footer = get_footer_for_mail()
    if request.method == "POST":
        form = MailForm(request, request.POST, request.FILES)
        if form.is_valid():
            mail = form.save()
            return redirect(reverse('posted', kwargs={'mail': mail.pk}))
    else:
        if request.user.is_anonymous():
            form = MailForm(request)
        else:
            form = MailForm(request,
                            initial={
                                'mfrom': request.user.email,
                                'name': request.user.full_name
                            })
    return locals()