Yorgos Pagles  committed 33cb60c

Tags set when sending email

  • Participants
  • Parent commits 57b6e9a

Comments (0)

Files changed (4)

-Email services for django providing various backends and respective statistics. Still very alpha.
+Django Email Services
+Email services for django providing various backends and respective statistics. Still alpha.
+Since this is still in alpha I wouldn't recommend using it in production environments (although the backends listed in this readme are working they have not been extensively used in a production environment).
+Currently it can be installed from the repository::
+    pip install -e hg+
 Current backends
 	In [4]: settings.EMAIL_SERVICES_CLIENT_KEY = 'your key depending on service'
 	In [5]: send_mail("subj", "body", "", ['', ""])
 	Out[5]: True
+Critsend exposes a SOAP API to interact with their service. The API works heavily with tags where we can store arbitrary information and then lookup statistics per tag.
+The Critsend service of django-email-services uses this feature each time an email is sent setting a tag to be the current site if the sites framework is installed. 

File email_services/services/

 from suds.client import Client
 from suds.transport.http import HttpTransport
+from django.contrib.sites.models import Site
 from email_services import settings
             setattr(campaign_params, "mailfrom_friendly", parseaddr(message.from_email)[0])
             setattr(campaign_params, "mailfrom", parseaddr(message.from_email)[1])
             if 'Reply-To' in message.extra_headers :
                 setattr(campaign_params, "replyto", parseaddr(message.extra_headers['Reply-To'])[1])
                 setattr(campaign_params, "replyto", parseaddr(message.from_email)[1])
+            tags_array = self.client.factory.create('ArrayTag')
+            if Site._meta.installed:
+                current_site = Site.objects.get_current()
+                tags_array.Tag.append(current_site.domain)
+                campaign_params.tag = tags_array
             emails = self.client.factory.create('ArrayEmail')
             for subscriber in

File email_services/

 from django.test import TestCase
 from django.core.mail import EmailMessage, EmailMultiAlternatives
+from django.contrib.sites.models import Site
 from email_services.backends import CritsendEmailBackend
 from import CritsendEmailService
         self.assertEquals(parameters_obj.mailfrom_friendly, from_name)
         self.assertEquals(parameters_obj.replyto, reply_to)
+    def test_email_tags(self):
+        """
+        Test that email messages tags are correctly set using the
+        critsend api
+        """
+        self.service.client = mock.Mock()
+        tags_obj = mock.Mock()
+        self.service.client.factory.create.return_value = tags_obj
+        tags_obj.Tag = []
+        msg = EmailMessage()
+        messages = [msg,]
+        self.service.send_messages(messages)
+        self.assertEquals(tags_obj.Tag[0], Site.objects.get_current().domain)
     def test_email_sending_subscribers(self):
         Test that email messages recipients are correctly set using the
       description="""A Django app providing email backends and respective service
-      objects for some of the most well known email services like Amazon SES and Critsend"""
+      objects for some of the most well known email services like Amazon SES and Critsend""",
       long_description=open("README.rst").read() + "\n" +
       keywords='django, mailing',