django-mailbox template error
Environment:
Request Method: GET
Request URL: http://hirewiz.tk/admin/django_mailbox/message/1/change/
Django Version: 1.9
Python Version: 3.6.2
Installed Applications:
['pages.apps.PagesConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_mailbox']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template error:
In template /usr/local/lib64/python3.6/site-packages/django/contrib/admin/templates/admin/change_form.html, error at line 32
2 22 : </div>
23 : {% endblock %}
24 : {% endif %}
25 :
26 : {% block content %}<div id="content-main">
27 : {% block object-tools %}
28 : {% if change %}{% if not is_popup %}
29 : <ul class="object-tools">
30 : {% block object-tools-items %}
31 : <li>
32 : {% url opts|admin_urlname:'history' orig inal.pk|admin_urlquo te as history_url %}
33 : <a href="{% add_preserved_filters history_url %}" class="historylink">{% trans "History" %}</a>
34 : </li>
35 : {% if has_absolute_url %}<li><a href="{{ absolute_url }}" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif %}
36 : {% endblock %}
37 : </ul>
38 : {% endif %}{% endif %}
39 : {% endblock %}
40 : <form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form" novalidate>{% csrf_token %}{% block form_top %}{% endblock %}
41 : <div>
42 : {% if is_popup %}<input type="hidden" name="{{ is_popup_var }}" value="1" />{% endif %}
Traceback:
File "/usr/local/lib64/python3.6/site-packages/django/db/models/options.py" in get_field
580. return self.fields_map[field_name]
During handling of the above exception ('envelope_headers'), another exception occurred:
File "/usr/local/lib64/python3.6/site-packages/django/contrib/admin/utils.py" in lookup_field
273. f = _get_non_gfk_field(opts, name)
File "/usr/local/lib64/python3.6/site-packages/django/contrib/admin/utils.py" in _get_non_gfk_field
307. field = opts.get_field(name)
File "/usr/local/lib64/python3.6/site-packages/django/db/models/options.py" in get_field
582. raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
During handling of the above exception (Message has no field named 'envelope_headers'), another exception occurred:
File "/usr/local/lib64/python3.6/site-packages/django/core/handlers/base.py" in get_response
174. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib64/python3.6/site-packages/django/core/handlers/base.py" in get_response
172. response = response.render()
File "/usr/local/lib64/python3.6/site-packages/django/template/response.py" in render
160. self.content = self.rendered_content
File "/usr/local/lib64/python3.6/site-packages/django/template/response.py" in rendered_content
137. content = template.render(context, self._request)
File "/usr/local/lib64/python3.6/site-packages/django/template/backends/django.py" in render
95. return self.template.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render
206. return self._render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in _render
197. return self.nodelist.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render
988. bit = node.render_annotated(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render_annotated
955. return self.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/loader_tags.py" in render
173. return compiled_parent._render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in _render
197. return self.nodelist.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render
988. bit = node.render_annotated(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render_annotated
955. return self.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/loader_tags.py" in render
173. return compiled_parent._render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in _render
197. return self.nodelist.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render
988. bit = node.render_annotated(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render_annotated
955. return self.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/loader_tags.py" in render
69. result = block.nodelist.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render
988. bit = node.render_annotated(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render_annotated
955. return self.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/loader_tags.py" in render
69. result = block.nodelist.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render
988. bit = node.render_annotated(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render_annotated
955. return self.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/defaulttags.py" in render
220. nodelist.append(node.render_annotated(context))
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render_annotated
955. return self.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/loader_tags.py" in render
209. return template.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render
208. return self._render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in _render
197. return self.nodelist.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render
988. bit = node.render_annotated(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render_annotated
955. return self.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/defaulttags.py" in render
220. nodelist.append(node.render_annotated(context))
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render_annotated
955. return self.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/defaulttags.py" in render
220. nodelist.append(node.render_annotated(context))
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render_annotated
955. return self.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/defaulttags.py" in render
326. return nodelist.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render
988. bit = node.render_annotated(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render_annotated
955. return self.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/defaulttags.py" in render
326. return nodelist.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render
988. bit = node.render_annotated(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render_annotated
955. return self.render(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in render
1039. output = self.filter_expression.resolve(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in resolve
705. obj = self.var.resolve(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in resolve
846. value = self._resolve_lookup(context)
File "/usr/local/lib64/python3.6/site-packages/django/template/base.py" in _resolve_lookup
909. current = current()
File "/usr/local/lib64/python3.6/site-packages/django/contrib/admin/helpers.py" in contents
194. f, attr, value = lookup_field(field, obj, model_admin)
File "/usr/local/lib64/python3.6/site-packages/django/contrib/admin/utils.py" in lookup_field
285. value = attr(obj)
File "/usr/local/lib/python3.6/site-packages/django_mailbox/admin.py" in envelope_headers
75. email = msg.get_email_object()
File "/usr/local/lib/python3.6/site-packages/django_mailbox/models.py" in get_email_object
728. return self._rehydrate(flat)
File "/usr/local/lib/python3.6/site-packages/django_mailbox/models.py" in _rehydrate
624. self._rehydrate(part)
File "/usr/local/lib/python3.6/site-packages/django_mailbox/models.py" in _rehydrate
653. attachment.document.read()
File "/usr/local/lib64/python3.6/site-packages/django/core/files/utils.py" in <lambda>
19. read = property(lambda self: self.file.read)
File "/usr/local/lib64/python3.6/site-packages/django/db/models/fields/files.py" in _get_file
51. self._file = self.storage.open(self.name, 'rb')
File "/usr/local/lib64/python3.6/site-packages/django/core/files/storage.py" in open
37. return self._open(name, mode)
File "/usr/local/lib64/python3.6/site-packages/django/core/files/storage.py" in _open
201. return File(open(self.path(name), mode))
Exception Type: FileNotFoundError at /admin/django_mailbox/message/1/change/
Exception Value: [Errno 2] No such file or directory: '/home/ec2-user/hirewiz/mailbox_attachments/2018/03/07/1c019db8888843908c5d243fd37c0df9.pdf'
If you look toward the bottom of the exception message you'll see that it's having trouble finding a file -- are you sure you're storing the mailbox attachments locally?
What message is that intended to convey to me?
You might have a mistaken understanding of how this library works; the messages are ingested by the library and it creates records and actual on-disk files are created during that ingestion process. Although I can see why you might think otherwise, whether your local mailbox exists or not is not relevant.
what i did i make a local email server and on signup i make directory by force and add to the mailbox
chown "+uname+"."+uname+" /home/"+uname+"/Maildir/{,cur,new,tmp}
That's fine -- you can create all of the Maildirs you want, but that doesn't answer the question. Do you see a file at /home/ec2-user/hirewiz/mailbox_attachments/2018/03/07/1c019db8888843908c5d243fd37c0df9.pdf on the actual machine running your Django instance?
yes 👍

You'll have to show that from your node running this -- whether you can see the path via some kind of mount on a different machine is not a useful test. The exception message you're seeing above is from the Django instance itself saying it can't find that file -- those messages are essentially never going to be wrong. It looks like you have some spelunking to do!
Also: you might notice that that file name you're showing there doesn't match the one it's looking for.
is it any thing wrong with the version django-mail i am using 1.9 downgrade from 1.10 ?
I'm afraid that this isn't likely to be a problem with this library, @zainali95; so downgrading won't help. It looks like it'll instead be a problem with how you have your production environment configured.
what you are saying is that django-mailbox is not able to fetch mails with cron job ?
No; that's not what I'm saying at all. What I'm saying is that your production environment is almost certainly configured in such a way that the files written while ingesting mail are not accessible to nodes running your UI.
if there is any permision issue let me know ?
chown "+uname+"."+uname+" /home/"+uname+"/Maildir/{,cur,new,tmp}
Just to be clear: this is not related to your maildir.
If I had to guess, I'd suppose you are ingesting your mail on different nodes than the ones that run your UI. In cases like that, you have to use either a different file storage backend -- see https://docs.djangoproject.com/en/1.11/ref/files/storage/, or share a single mountpoint across all of your nodes. That's not anything related to django-mailbox itself, though, but but how files are handled in Django.
What I do for my projects, in this kind of scenario, is use django-storages and their S3BotoStorage backend.
i am using single instace for mail and website :/
Then I'm not clear on why you don't see that file it's looking for; do you have an alternate explanation?
i wonder why i am getting the subject of email but not the message and attachment at admin

I'm afraid the level of help you might need for sorting this out is more than I have time to give. The messages are stored as records in the database -- that's why you can see the subject there -- but the attachments are stored on the filesystem as normal files. The error you're getting is because it can't find the files it thinks it wrote to the filesystem when ingesting your messages.
The challenge you have, now, is figuring out why the files it's writing to the filesystem during ingestion aren't there when it tries to find them later.
is there any way to generate message and message_attachments cause i think it has no rights to django mail has -rw as i created these two dir mannually after deleting accidentally
that was really my dummiest mistake i forgot / after Maildir/ in uri
I am using Django-mailbox, AWS-EC2 instance and AWS-S3 , So I am trying to send an attachment with mail and receive it on S3 bucket and I am successful to achieve this.
Next while accessing that attachment file from saved path, it showing me following error, however file is saved successfully in given path, you can see in folder dir.
My folder structure is as follows
Let me know if any further details needed.
How did you get to the URL you've posted the "Page Not Found" for?
i wonder why i get Page Not Found if the file is present and names are same
I think you might be under the impression that Django apps work like simple PHP apps do, and that your filesystem might somehow map directly to URLs. That is not how it works. If you want to make a file on your filesystem accessible via a URL, you'll need to create a new route and view. The details of how that works are beyond this conversation, though, but you can find Django tutorials all over the internet.
no it's not that u might taking wrong .let me clearify you admin application view are of your responsibility .Yes i know that the piece o code that i write works on frontend now on admin panel
I don't understand your reply, @zainali95, and it seems like our lack of a common language is going to be an obstacle. Let me try to speak as plainly as I can:
The following things are all true:
- The URL you've posted above is invalid, and I'm not sure how you obtained a link to that URL.
- An "E-mail message object" is an instance of this model: https://github.com/coddingtonbear/django-mailbox/blob/master/django_mailbox/models.py#L453 (see https://github.com/coddingtonbear/django-mailbox/blob/master/django_mailbox/models.py#L743)
- A "Primary Key" is database terminology for "unique identifier". In Django, these are almost always integers.
- The view you have landed on has an error message reading
E-mail message object with primary key '14/change/mailbox_attachments/2018/03/12/b6ecdc8c11854497abc7cc84ae49a025.xslx' does not exist.because you've landed on the built-in Django Admin's change view, and its route uses the everything after/admin/django_mailbox/message/and before/change/as the ID (AKA "primary key") of the database reocrd to look up and display. In this instance, it's expecting an integer -- probably just the14. - This is the route you're accessing: https://github.com/django/django/blob/master/django/contrib/admin/options.py#L590.
- This is the view you're accessing: https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1576
can u come on skype ?
No; I am writing to you from work in between working on tasks and have very little time to spare.

