Whatever the reason is, you may want to save the Sends history in a data extension. This may allow you to extract this data for an external BI tool, or save the HTML message associated to each user for each send, etc…
So the idea would be to place an AMPSCRIPT code in each of your emails. A best practice would be to create an HTML content, and re-use it in all your templates / messages, by referring to its ID:
Prepare your data extension
First, you should create the data extension dedicated to save the Send data. No need to explain this part, unless you ask for this :)
Create your script
The AMPSCRIPT code to be written should:
- launch only when the email is sent (not previewed)
- save the wanted fields to the data extension
Here it is, commented:
%%[ if _messagecontext == "SEND" and jobid > 0 then /* the message context is an actual deployment, not a test or preview */ InsertDE("sendLog", /* the name of the data extension */ "SUBSCRIBERKEY", _subscriberkey, /* map your DE field with the value */ "EMAILADDRESS", Email, "SENT_EMAIL", emailname_, "SENT_DATE", Now() ) EndIf ]%%
In order to create such a script, you may need information about:
- Message Context and Personalization strings (emailname_, _subscriberkey, etc…)
- InsertDE AMPSCRIPT function
- Now() AMPSCRIPT function
How to save the HTML message for each user ?
Now, you can save any information you may want into your Data Extension. In other terms, you may use this data extension to save the HTML of the email that will be received by each recipient, including personalization. The ideal way to perform this is to retrieve the code of the web-page (aka ‘mirror’ page):
%%[ IF _messagecontext == "SEND" AND jobid > 0 THEN set @HTML = HTTPGet(view_email_url) InsertDE("sendHistory", "JobID",jobid, "SubscriberKey",_subscriberkey, "EventDate",NOW(), "HTML",@HTML ) ENDIF ]%%
Here, we set an @HTML variable, that will retrieve the web page content via an HTTPGET function. This variable is then saved in the « HTML » field of the data extension.
Solve the « open count » issue
The drawback of using the HTTPGET function on the web page is that an OPEN will be counted at the time of the send. The code of the page is executed, so the open tag will be launched. In order to avoid counting an OPEN when the mirror page is called, you can use some Message Context conditions in order to only show the open counter when the context is the SEND or the VAWP (View As Web Page). This code has to be applied to all your emails containing the Send history feature:
%%[ IF _messagecontext == "SEND" OR _messagecontext == "VAWP" THEN ]%% <custom name="opencounter" type="tracking"> %%[ ENDIF ]%%
This conditional OPEN counter will make the trick !