bameda / djmail Goto Github PK
View Code? Open in Web Editor NEWSimple, powerfull and nonobstructive django email middleware.
Home Page: http://bameda.github.io/djmail/
License: Other
Simple, powerfull and nonobstructive django email middleware.
Home Page: http://bameda.github.io/djmail/
License: Other
I am implementing a Notifications feature and I'd like to connect the notification with the email sent, for that I included something like the following to my Notification model.
email_message = models.OneToOneField(
djmail_models.Message,
on_delete=models.SET_NULL,
null=True,
blank=True,
verbose_name=_("Email message"),
)
But I don't know how to later match this, the only thing that I was able to come up with was:
self.email_message = djmail_models.Message.objects.filter(
body_html__icontains=self.id
).first()
But that is not optimal, is there a way to get the uuid or model instance for example when the email is sent? or how should I go about doing this? I send the email this way:
email_builder = template_mail.MagicMailBuilder()
context = {
...
}
email = email_builder.notification(self.recipient, context)
email.send() # <---------- it would be cool to have something like "djmail_message = email.send()"
>>> email.send()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/vagrant/env/lib/python2.6/site-packages/django/core/mail/message.py", line 276, in send
return self.get_connection(fail_silently).send_messages([self])
File "/vagrant/env/lib/python2.6/site-packages/djmail/backends/base.py", line 24, in send_messages
return self._send_messages(email_messages)
File "/vagrant/env/lib/python2.6/site-packages/djmail/backends/default.py", line 13, in _send_messages
return core._send_messages(email_messages)
File "/vagrant/env/lib/python2.6/site-packages/djmail/core.py", line 80, in _send_messages
for email in email_messages]
File "/vagrant/env/lib/python2.6/site-packages/djmail/models.py", line 76, in from_email_message
instance.save()
File "/vagrant/env/lib/python2.6/site-packages/django/db/models/base.py", line 545, in save
force_update=force_update, update_fields=update_fields)
File "/vagrant/env/lib/python2.6/site-packages/django/db/models/base.py", line 573, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/vagrant/env/lib/python2.6/site-packages/django/db/models/base.py", line 635, in _save_table
forced_update)
File "/vagrant/env/lib/python2.6/site-packages/django/db/models/base.py", line 679, in _do_update
return filtered._update(values) > 0
File "/vagrant/env/lib/python2.6/site-packages/django/db/models/query.py", line 510, in _update
return query.get_compiler(self.db).execute_sql(None)
File "/vagrant/env/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 980, in execute_sql
cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
File "/vagrant/env/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
cursor.execute(sql, params)
File "/vagrant/env/lib/python2.6/site-packages/django/db/backends/util.py", line 69, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/vagrant/env/lib/python2.6/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/vagrant/env/lib/python2.6/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/vagrant/env/lib/python2.6/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/vagrant/env/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py", line 452, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: no such table: djmail_message
I think we are missing a migration here.
Line 20: from . import exceptions as exc in djmail/template_mail.py
Error Traceback:
ImproperlyConfigured: "cannot import name exceptions"
There doesn't seem to be an exceptions module anywhere
The t should be a d:
Hello,
During #32 pull requests I identified uncompatibility with django 1.10 with following erros:
======================================================================
ERROR: test_simple_send_email_with_magic_builder_1 (djmail.tests.SerializationEmailTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 79, in _render_message_subject
subject = loader.render_to_string(template_name, context)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 67, in render_to_string
template = get_template(template_name, using=using)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 25, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: emails/test_email2-subject.html
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/test/utils.py", line 208, in inner
return func(*args, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/tests.py", line 275, in test_simple_send_email_with_magic_builder_1
email = mails.test_email2('[email protected]', {'name': 'foo'})
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 159, in _dynamic_email_generator
email_instance = template_email.make_email_object(to, context, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 90, in make_email_object
subject = self._render_message_subject(context)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 81, in _render_message_subject
raise exc.TemplateNotFound("Template '{0}' does not exists.".format(e))
djmail.exceptions.TemplateNotFound: Template 'emails/test_email2-subject.html' does not exists.
======================================================================
ERROR: test_proper_handlign_different_uses_cases (djmail.tests.TestTemplateEmailSending)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 79, in _render_message_subject
subject = loader.render_to_string(template_name, context)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 67, in render_to_string
template = get_template(template_name, using=using)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 25, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: emails/test_email1-subject.html
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/build/ad-m/djmail/djmail/tests.py", line 212, in test_proper_handlign_different_uses_cases
context={'name': 'foo'})
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 173, in make_email
return instance.make_email_object(to, context, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 90, in make_email_object
subject = self._render_message_subject(context)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 81, in _render_message_subject
raise exc.TemplateNotFound("Template '{0}' does not exists.".format(e))
djmail.exceptions.TemplateNotFound: Template 'emails/test_email1-subject.html' does not exists.
======================================================================
ERROR: test_simple_email_building (djmail.tests.TestTemplateEmailSending)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 79, in _render_message_subject
subject = loader.render_to_string(template_name, context)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 67, in render_to_string
template = get_template(template_name, using=using)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 25, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: emails/test_email1-subject.html
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/build/ad-m/djmail/djmail/tests.py", line 202, in test_simple_email_building
context={'name': 'foo'})
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 173, in make_email
return instance.make_email_object(to, context, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 90, in make_email_object
subject = self._render_message_subject(context)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 81, in _render_message_subject
raise exc.TemplateNotFound("Template '{0}' does not exists.".format(e))
djmail.exceptions.TemplateNotFound: Template 'emails/test_email1-subject.html' does not exists.
======================================================================
ERROR: test_simple_send_email_1 (djmail.tests.TestTemplateEmailSending)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 79, in _render_message_subject
subject = loader.render_to_string(template_name, context)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 67, in render_to_string
template = get_template(template_name, using=using)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 25, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: emails/test_email1-subject.html
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/test/utils.py", line 208, in inner
return func(*args, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/tests.py", line 138, in test_simple_send_email_1
email.send('[email protected]', {'name': 'foo'})
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 117, in send
email = self.make_email_object(to, context, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 90, in make_email_object
subject = self._render_message_subject(context)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 81, in _render_message_subject
raise exc.TemplateNotFound("Template '{0}' does not exists.".format(e))
djmail.exceptions.TemplateNotFound: Template 'emails/test_email1-subject.html' does not exists.
======================================================================
ERROR: test_simple_send_email_2 (djmail.tests.TestTemplateEmailSending)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 79, in _render_message_subject
subject = loader.render_to_string(template_name, context)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 67, in render_to_string
template = get_template(template_name, using=using)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 25, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: emails/test_email2-subject.html
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/test/utils.py", line 208, in inner
return func(*args, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/tests.py", line 155, in test_simple_send_email_2
email.send('[email protected]', {'name': 'foo'})
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 117, in send
email = self.make_email_object(to, context, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 90, in make_email_object
subject = self._render_message_subject(context)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 81, in _render_message_subject
raise exc.TemplateNotFound("Template '{0}' does not exists.".format(e))
djmail.exceptions.TemplateNotFound: Template 'emails/test_email2-subject.html' does not exists.
======================================================================
ERROR: test_simple_send_email_with_magic_builder_1 (djmail.tests.TestTemplateEmailSending)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 79, in _render_message_subject
subject = loader.render_to_string(template_name, context)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 67, in render_to_string
template = get_template(template_name, using=using)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 25, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: emails/test_email2-subject.html
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/test/utils.py", line 208, in inner
return func(*args, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/tests.py", line 171, in test_simple_send_email_with_magic_builder_1
email = mails.test_email2('[email protected]', {'name': 'foo'})
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 159, in _dynamic_email_generator
email_instance = template_email.make_email_object(to, context, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 90, in make_email_object
subject = self._render_message_subject(context)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 81, in _render_message_subject
raise exc.TemplateNotFound("Template '{0}' does not exists.".format(e))
djmail.exceptions.TemplateNotFound: Template 'emails/test_email2-subject.html' does not exists.
======================================================================
ERROR: test_simple_send_email_with_magic_builder_1_with_extra_kwargs (djmail.tests.TestTemplateEmailSending)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 79, in _render_message_subject
subject = loader.render_to_string(template_name, context)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 67, in render_to_string
template = get_template(template_name, using=using)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 25, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: emails/test_email2-subject.html
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/test/utils.py", line 208, in inner
return func(*args, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/tests.py", line 189, in test_simple_send_email_with_magic_builder_1_with_extra_kwargs
from_email="[email protected]")
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 159, in _dynamic_email_generator
email_instance = template_email.make_email_object(to, context, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 90, in make_email_object
subject = self._render_message_subject(context)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 81, in _render_message_subject
raise exc.TemplateNotFound("Template '{0}' does not exists.".format(e))
djmail.exceptions.TemplateNotFound: Template 'emails/test_email2-subject.html' does not exists.
======================================================================
ERROR: test_simple_send_email_with_magic_builder_1_with_low_priority (djmail.tests.TestTemplateEmailSending)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 79, in _render_message_subject
subject = loader.render_to_string(template_name, context)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 67, in render_to_string
template = get_template(template_name, using=using)
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/template/loader.py", line 25, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: emails/test_email2-subject.html
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages/django/test/utils.py", line 208, in inner
return func(*args, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/tests.py", line 236, in test_simple_send_email_with_magic_builder_1_with_low_priority
email = mails.test_email2('[email protected]', {'name': 'foo'}, priority=10)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 159, in _dynamic_email_generator
email_instance = template_email.make_email_object(to, context, **kwargs)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 90, in make_email_object
subject = self._render_message_subject(context)
File "/home/travis/build/ad-m/djmail/djmail/template_mail.py", line 81, in _render_message_subject
raise exc.TemplateNotFound("Template '{0}' does not exists.".format(e))
djmail.exceptions.TemplateNotFound: Template 'emails/test_email2-subject.html' does not exists.
----------------------------------------------------------------------
Body is not always text/plain but sometimes text/html 746236d.
However this https://github.com/niwibe/djmail/blob/master/djmail/models.py#L67 always sets body_text to email.body even if this is text/html.
The GitHub Pages site that hosts the documentation no longer exists: http://bameda.github.io/djmail/
The html content of an email is displayed as code.
It would be much more useful to see the rendered html.
The possibility to see the raw html is great. It should just not be the default output.
I ran into an issue where the DNS entry for the specified host stopped resolving to anything. In this case, all messages marked for sending ended up with a status of draft. I'm assuming that's because djmail knew better than try to send them in the first place, which is fine. The problem is that there was no way for me to resend once the underlying issue was resolved without manually updating the status to something that the resend management command could use (I chose pending).
Celery defaults the setting CELERY_TASK_SERIALIZER
to 'picke'
so there is no guarantee that a Django project will set it.
https://docs.djangoproject.com/en/1.10/releases/1.10/#features-removed-in-1-10
The class BaseCommand should be used instead: https://docs.djangoproject.com/ja/1.10/internals/deprecation/#deprecation-removed-in-1-10
Note:
Subclassing the BaseCommand class requires that you implement the handle() method.
Hi
I forgot to put DEFAULT_FROM_EMAIL = EMAIL_HOST_USER to simplify email sending.
It caused a big problem - email sending went into an infinite loop which caused to generate over 5000 email objects in the database.
If I only have the body-html version of the template, this doesn't work correctly, the mails apear in the mail client in text but his content is HTML.
When switching to the Celery back-end I have an issue: The parameters for the task, "emails" are instances of django.core.mail.message.EmailMessage or EmailMultiAlternatives. There are both not serializable to JSON. We do not use pickle as recommended by Celery's documentation.
I will look at it tomorrow but in the meantime if you have any idea to fix it, thanks for sharing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.