Hi,
I am trying to generate pdf file and send the generated file by mail
to the user.
But I am getting value error as I am not sure how to attach file.

here is my view function:

def companies_report(request, companyid):
    _user = request.user
    sender = _user.email
    company = Company.objects.get(id= companyid)
    response = HttpResponse(mimetype='application/pdf')
    response['Content-Disposition'] = 'attachment;
filename=report1.pdf'

    p = canvas.Canvas(response)
    p.drawString(100, 100, "Hello world.")

    p.showPage()
    p.save()
    try:
        subject = "Company Report"
        message = "Company report"
        send_to = _user.email
        attach = response
        mail = EmailMessage(subject, message, sender,[send_to])
        mail.attach(attach.name, attach.read(), attach.content_type)
        mail.send()
    except Exception, e:
        raise ValueError, e
    request.user.message_set.create(message="Mail sent successfully.")
    return HttpResponseRedirect('../')

The problem here is if I say attach = response then I am getting error
'HttpResponse' object has no attribute 'name'
So my question is how to attach the generated file in EmailMessage.

Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to