artemrizhov / django-mail-templated Goto Github PK
View Code? Open in Web Editor NEWSend emails using Django template system
License: MIT License
Send emails using Django template system
License: MIT License
Improve the method signatures, add list of properties and methods.
It seems when i load a template with only {% block html %}<strong>Text</strong>{% endblock %}
mail is sent as a text/plain message. Anyone having this issue?
Full template looks like this
{% extends 'mail_templated/base.tpl' %}
{% block subject %}
Din bruger på Klinikker.dk
{% endblock %}
{% block html %}
<h1>Hello there</h1>
{% endblock %}
send_mail
function should compile messages by default. This should fix the serialization problem described in #7.
When i create message, i take mistake:
AttributeError at /
'NoneType' object has no attribute 'splitlines'
Request Method: POST
Request URL: http://127.0.0.1:8080/
Django Version: 1.11.7
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'splitlines'
Exception Location: /var/www/lf/lib/python3.5/site-packages/django/core/mail/message.py in set_payload, line 224
Python Executable: /var/www/lf/bin/python
Python Version: 3.5.3
Python Path:
['/var/www/lf/lFD',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/var/www/lf/lib/python3.5/site-packages',
I take settings from docs.
Is it incompatibility or Did i mistake anywhere?
Exception should be thrown in EmailMessage.__init__()
when render and not template_name
.
Thanks to @jonashaag for pointing on this problem. Discussion is here: a5f5621
Шалом.. как сам? Привет из Тбилиси
Is there a way to load template from string rather than file?
Hey, had the same issue with my lib (vintasoftware/django-templated-email#3) with a caveated fix here - https://github.com/bradwhittington/django-templated-email/blob/867ef61693d02a39ca902a30e66d5dd7dd941cda/templated_email/utils.py
It breaks when you don't have blocks for subject/body/etc. in the template you render, but do have them in the template you extend
My solution is a messy hack, but after diving into the template code I couldn't find a better solution. Would love to see a neater, more comprehensive one (this breaks for {{block.super}})
It is not possible now, right? I would really like to see this.
Hello, is there a way i can iterate a list in my html email template?
i tried creating it before passing to the context as well with no luck:
not_in_db_html = "<ul>"
for db in sorted(not_in_db):
not_in_db_html += "<li>" + db + "</li> "
not_in_db_html += "</ul>"
it displays as a string in my email
This will help to ensure the class behaviour will not change accidentally.
Also more explanations in the README file may be needed.
Hi,
I'm having difficulties using django-mail-templated. When I tried to send email through form, I get this error :
(I'm pretty sure the template is exsist in there. I'm using Djrill plugin and Django 1.9)
MandrillAPIError at /order/
Sending a message to [email protected] from [email protected]
Mandrill API response 500:
{
"status": "error",
"message": "No such template \"email/order_email.html\"",
"code": 5,
"name": "Unknown_Template"
}
This is my views.py
from mail_templated import send_mail
@login_required
def order_form(request):
if request.method == "POST":
form = OrderForm(request.POST, request.FILES)
if form.is_valid():
order = form.save(commit=False)
order.tanggal_order = datetime.datetime.now()
order.save()
from_email = '[email protected]'
send_mail('email/order_email.html', {'order': order}, from_email, [order.email])
return render(request, 'order_app/order_success.html')
else:
form = OrderForm()
return render(request, 'order_app/order_form.html', {'form': form})
My order_email.html template:
{% extends "email/base.html" %}
{% block subject %}
Hello {{ order.nama }}
{% endblock %}
{% block html %}
This is an <strong>{{ order.id }}</strong> message.
{% endblock %}
My app directory tree :
Thank you in advance for any help you can provide :)
Regards,
When I install this package via pip, I am getting this warning.
WARNING: Generating metadata for package django-mail-templated produced metadata for project name dabapps-django-mail-templated. Fix your #egg=django-mail-templated fragments.
Please fix this.
Hello, my django version is 1.9.2, when I send_mail with mail_templated has warning like this:
WARNING:py.warnings::/usr/local/lib/python2.7/dist-packages/mail_templated/message.py:174: RemovedInDjango110Warning: render() must be called with a dict, not a Context.
result = self.template.render(context)
I know this does not affect to use, but if replace Context with dict is easy, I think it is a good idea for compatibility.
I love this package, thank you ~
Hi,
I've noticed that you use super incorrectly:
class EmailMessage(mail.EmailMultiAlternatives):
...
def __init__(self, template_name, context, *args, **kwargs):
...
# super(mail.EmailMultiAlternatives, self).__init__(*args, **kwargs) # incorrect
super(EmailMessage, self).__init__(*args, **kwargs) # correct
BTW great lib, keep on working ;).
https://github.com/jonashaag/django-mail-templated-simple
Just posting this here if someone else has issues with serialization or django-celery-email.
Maybe you could explain why you had to make your implementation so complicated? I'm not saying you should change it. Just wondering...
If I forget to inherit from the base template provided with django-mail-templated, I'll get some cryptic error like this:
Traceback (most recent call last):
File "mail_templated/message.py", line 227, in send
return super(EmailMessage, self).send(*args, **kwargs)
File "django/core/mail/message.py", line 292, in send
return self.get_connection(fail_silently).send_messages([self])
File "django/core/mail/backends/locmem.py", line 26, in send_messages
message.message()
File "django/core/mail/message.py", line 255, in message
msg = SafeMIMEText(self.body, self.content_subtype, encoding)
File "django/core/mail/message.py", line 171, in __init__
MIMEText.__init__(self, _text, _subtype, None)
File "email/mime/text.py", line 34, in __init__
_text.encode('us-ascii')
AttributeError: 'NoneType' object has no attribute 'encode'
This should be caught earlier if possible and turned into a nice error message.
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.