Anonymous avatar Anonymous committed 474c9ae

Added support for HTML emails
Gave easier access to multi-value form fields

Comments (0)

Files changed (2)

gnocchi/mail/models.py

     email_to = models.CharField(max_length=1024)
     email_from = models.CharField(max_length=80)
     redirect_to = models.ForeignKey('cms.Page', related_name='+')
+    as_html = models.BooleanField(default=False)
     class Meta:
         verbose_name = 'Email Form'

gnocchi/mail/views.py

 from django.template import RequestContext, Template
 from django import http
-from django.core.mail import send_mail
+from django.core.mail import EmailMessage
 from django.views.decorators.csrf import csrf_exempt
 from django.shortcuts import get_object_or_404
 
 
     ctx = RequestContext(request, {
         'data': request.POST,
+        'lists': dict(request.POST.iterlists()),
         'request': request}
     )
     tmpl = Template(obj.template.content)
-    send_mail(obj.subject,
-        tmpl.render(ctx),
-        obj.email_from,
-        obj.email_to.split(','),
+    msg = EmailMessage(
+        subject = obj.subject,
+        body = tmpl.render(ctx),
+        from_email = obj.email_from,
+        to=[rcpt.strip() for rcpt in obj.email_to.split(',')]
     )
+    if obj.as_html:
+        msg.content_subtype = 'html'
+    msg.send(fail_silently=True)
+
     return http.HttpResponseRedirect(obj.redirect_to.get_absolute_url())
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.