示例#1
0
def index(request):
    '''
    Index page.
    Also that view serve feedback(message) form submission, if http request type is POST(request.method == POST)
    '''
    form = FeedbackForm()
    projects = get_list_or_404(Project)
    for item in projects:
        item.image = item.get_images()[0]
    # Show hello for first time visit 
    request.session['show_hello'] = False
    show_hello = request.session.get('show_hello', True)
    # debug
    context = {'form': form, 'projects': projects, "show_hello": True} # show_hello }
    # Send message
    if request.method == "POST":
        form = FeedbackForm(request.POST or None)
        context['form'] = form
        if form.is_valid():
            # Save form into new Message object
            form.save()
            # Send email
            email = Email(subject=form.author, message=form.message, address=form.email)
            # debug
            print(email.__dict__)
            send_email(email.subject, email.message, email.sent_from, [email.address], fail_silently=False)
            return HttpResponse("HTTP 200 OK")
        else:
            return HttpResponse("HTTP 404")
    return render_to_response('portfolio/index.html', context, context_instance=RequestContext(request))
示例#2
0
def send_mail(request):
    contactdetails = ContactDetails.objects.last()
    template = 'contact/contact.html'

    if request.method == 'POST' :
        contact_form = ContactForm(request.POST)
        if contact_form.is_valid():
            # name = contact_form.cleaned_data['name']
            from_email = contact_form.cleaned_data['from_email']
            subject = contact_form.cleaned_data['subject']
            message = contact_form.cleaned_data['message']

            try :
                send_email( from_email , subject , message , ['*****@*****.**'])

            except BadHeaderError :
                messages.add_message(request, messages.ERROR, 'Invalid header')

            messages.add_message(request, messages.SUCCESS, 'Message Sent Successfully')
            return HttpResponseRedirect('/')

    else:
        contact_form = ContactForm()


    context = {
        'contactdetails' : contactdetails  ,
        'contact_form' : contact_form
    }

    return render(request, template , context)
def send_email_post(request: HttpRequest):
    # Generate the unique Token and the URL
    user_email = request.POST.get('email', '')
    user_token = Token.objects.create(email=user_email)
    unique_url = request.build_absolute_uri(reverse('login') + f'?token={user_token.uid}')
    send_email(recipient_list=[user_email],
               from_email='me',
               subject='Your login link for Superlists',
               message=f'This is your login link for Superlists. Simply click it and you will be logged in!\n{unique_url}')
    messages.success(request, 'Your unique login URL has been sent! Please check your e-mail.')
    return redirect('/')
示例#4
0
def enviar_email(conteudo):
    """Método responsável
    por enviar e-mails pelo sistema.
    
    Os parametros são:
      - subject: Título do E-mail;
      - message: caminho do arquivo
      que contém o template do e-mail
      para renderização
    """
    message = render_to_string("email/fale_conosco.txt", {"conteudo": conteudo})

    send_email(
        subject=subject, message=message, from_email=settings.DEFAULT_FROM_EMAIL, recipient_list=[conteudo.email]
    )
示例#5
0
def send_mail_to_author(sender, instance, created, **kwargs):
    if created:
        request = instance.request

        request.session[str(instance.pk)] = True

        context = {
            'post': instance.target,
        }
        subject = render_to_string('blog/mail/comment_notify_subject.txt',
                                   context, request)
        message = render_to_string('blog/mail/comment_notify_message.txt',
                                   context, request)
        from_email = settings.DEFAULT_FROM_EMAIL
        recipient_list = [settings.DEFAULT_FROM_EMAIL]
        send_email(subject, message, from_email, recipient_list)