##View In Browser functionality for Sparkpost
This project was built to satisfy the need of having a View In Browser capability usable with SparkPost.
The code takes in a BCC of a message and presents it for Web Browser viewing. It uses a random number and the current timestamp to provide a UUID to identify a specific message.
The code comes in two parts.
- A component that creates a link with the UUID that can be added to the message content
- A component to store a copy in a Web service for viewing after some time.
Arguably a 3rd component is the administration tool of the web service that allows you to control how long messages are stored.
genkey.php - an API that accepts an email address, and campaign_id, creates a hash and returns it for use as the ViewInBrowser link.
econsumer.php - This will take in a relay-webhook from Sparkpost and save the HTML and TEXT parts as files for later viewing. Be sure to create a valid inbound domain first
Once you have set up your web server, go to your SparkPost account and set up a couple of things:
First, you must ensure that you have registered an inbound domain in your SparkPost account
Next, you need to setup the Inbound Relay-Webhook to point to your VIB project. When you configure the relay_webhook, I highly recommend using an AuthToken so you can validate the inbound traffic.
When you are creating a message, first execute the genkey.php script. You can do this remotely from any web browser and just copy and paste the provided link, or you can use it programmatically. eg: wget /genkey.php. This will produce something like https://<your_server>/<your_app>/vib?l=1516749514104287
Now use that link as the View In Browser link. For example, at the top of the message you can add something like this:
Click HERE to view this message in your web browser.
Again, this can be done programmatically very easily, or you can do it manually.
Now when you send the message, you need to BCC your VIB app so that it can create viewable images. You do this by sending a copy to the inbound domain you defined earlier. The local part is irrelevant, so if your inbound domain is "mynewserver.com", then you can BCC the message to "email@example.com" and let the code to all the rest.
Feel free to clone, copy, branch and leave any comments or suggestions in the repo.