Please I need help in solving this.
The “read” method on the doc object shows this error:
ValueError: I/O operation on closed file.
def send_comment_mail_notification(request, space, target_email):
message = request.POST.get('description', '')
subject = request.POST.get('subject', '')
from_mail = space.email
to = target_email
msg = EmailMessage(subject, message, from_mail, [to],)
doc = request.FILES['document']
print(doc.read())
msg.attach(doc.name, doc.read(), doc.content_type)
msg.content_subtype = "html"
msg.send()
class CommentViewSet(BaseViewSet):
permission_classes = (BelongToSpace, )
serializer_class = serializers.CommentSerializer
parser_classes = (MultiPartParser, FormParser, FileUploadParser)
queryset = models.Comment.objects.all()
def callback(self, **kwargs):
return send_comment_mail_notification(self.request, self.space, "aa@gmail.com")