I needed to track wether or not an user opened a notification email sent by my app (to prevent spamming him with further emails). So I embedded an img-Tag in the email pointing to something like https://myhost.com/:identifier.gif.
Now I had to find out about two things:
- The smallest possible gif there is
- How to serve an image from a Phoenix controller
For the first one I found this Github repo by mathiasbynens with a huge list of all kinds of file types and their smallest possible valid representation.
I downloaded the gif from the repo, opened an IEx shell and loaded the file. Then I printed the bitstring representation to the console and copy&pasted it into my controller.
For the second part I just googled my problem and found a simple example on stackoverflow.
Then I put it all together and this is the result:
And in the email template I put something like this at the end:
BTW on how to more comfortable send emails in Elixir Phoenix I wrote a post about it here.