GithubHelp home page GithubHelp logo

bameda / djmail Goto Github PK

View Code? Open in Web Editor NEW
77.0 10.0 25.0 191 KB

Simple, powerfull and nonobstructive django email middleware.

Home Page: http://bameda.github.io/djmail/

License: Other

HTML 0.40% Shell 0.85% Python 98.75%

djmail's Introduction

djmail

image

djmail is a BSD Licensed, simple and nonobstructive django email middleware.

Why use djmail? Because it:

  • Sends emails asynchronously without additional libraries.
  • Sends emails using celery tasks.
  • Can retry sending failed messages (with cron task or celery periodic task).
  • Can assign delivery priority.
  • Has a powerful class to build emails from templates.
  • Works transparently (works as middleware for native django email backends)

djmail was created by Andrey Antukh (@niwinz) and is maintained by David Barragán (@bameda).

You can read the full documentation at https://bameda.github.io/djmail/.

djmail's People

Contributors

ad-m avatar bameda avatar curiouslearner avatar davidfischer-ch avatar jdruiter avatar jespino avatar klen avatar mauricioabreu avatar mhindery avatar niwinz avatar thijstriemstra avatar timgates42 avatar zopieux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

djmail's Issues

Tests fails in django 1.10

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.
----------------------------------------------------------------------

dns resolution failure for EMAIL_HOST blackholes messages

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).

Rendering of HTML content

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.

Improper import in template_mail.py

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

obtain Message instance after email send

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()"

Migration missing?

>>> 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.

Celery backend: Handle other serializers than pickle (JSON)

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.