예제 #1
0
파일: views.py 프로젝트: armenav/a2b
def mail_from_postmark(request):
        if request.method == 'POST':
                json_data = request.body
                #body = json.loads(json_data)['HtmlBody']
                inbound = PostmarkInbound(json=json_data)
                if inbound.has_attachments():
                    attachments = inbound.attachments()
                    names = []
                    #absolue_uri = "<a href='"+request.build_absolute_uri(name1)+"'>" + name + "</a>"
                    for attachment in attachments:
                        name = attachment.name()
                        name1 = settings.MEDIA_URL + 'attachments/' + name
                        name2 = settings.MEDIA_ROOT + '/attachments/' + name                        
                        names.append(name1)
                        with open(name2,'w') as f:
                            myFile = File(f)
                            myFile.write(attachment.read())
                    mail = Inboundmail(html_body=inbound.text_body(), send_date=inbound.send_date(), subject=inbound.subject(), reply_to=inbound.reply_to(), sender=inbound.sender(), attachment=','.join(names))
                    #pdb.set_trace()
                else:
                    mail = Inboundmail(html_body=inbound.text_body(), send_date=inbound.send_date(), subject=inbound.subject(), reply_to=inbound.reply_to(), sender=inbound.sender())
                mail.save()
                return HttpResponse('OK')
        else:
                return HttpResponse('not OK')
예제 #2
0
파일: views.py 프로젝트: davit-gh/taxishare
def mail_from_postmark(request):
        if request.method == 'POST':
                json_data = request.body
                body = json.loads(json_data)['HtmlBody']
                inbound = PostmarkInbound(json=json_data)
                mail = Inboundmail(html_body=inbound.text_body(), send_date=inbound.send_date(), subject=inbound.subject(), reply_to=inbound.reply_to(), sender=inbound.sender())
                mail.save()
                return HttpResponse('OK')
        else:
                return HttpResponse('not OK')