I just finished some email tracking software, and I’m going to explain very quickly how it works.
My newsletter sender appends a specific image to the end of the email, with a specific get request that identifies the recipient.
Lets say I have a subscriber model, full of emails. I send the email: “Hello”
subscriber = Subscriber(firstname.lastname@example.org', name='Yuji Tomita') subject = 'testing open tracking' body = "hello' new_body = body + '<img src="/open-tracking/?id=%s" />' % (subscriber.id) send_html_mail(subject, new_body, "email@example.com", [subscriber.email])
This sends an email with an image embedded that identifies the subscriber.
Now, for the view to handle the image request. It must return a valid image or else your html email will often have a broken image icon. Here’s how to pass back an image in django:
def track-open-emails(request): if 'id' in request.GET: #do something with the id, which tells you that specific subscriber has opened the email. #do something to record that an email has been opened. image_data = open("/path_to_image/", 'rb').read() return http.HttpResponse(image_data, mimetype="image/png")