View sent emails in activities
Overview
As it stands currently, a CiviCRM user can send an email to a contact via a few methods. The user can also use tokens which personalise the content per contact they are sending an email too.
On submission, an activity is created for this. However, the activity only stores the tokens and not the actual content sent to a contact.
The behaviour for how the content of the email when we use the “send email” activity functionality is different to that from mass mailings with respect to tokens, and any used tokens aren’t replaced in the resultant stored body of the content in the activity with the actual content.
To see the content of the sent email (rather than just “token” itself) is important to users as
- They should be able to see what was sent to a contact at any given time and not just the tokens
- information might change with time i.e. the data in the field may change so the user will not know what was actually sent to the contact
Current behaviour
A mailing can be sent to the user in multiple ways in CiviCRM eg. bulk mailings, through send email activity on the contact record, inside a case, scheduled reminders, and through extensions like CiviRules.
However, when we use the send email activity form, any used tokens aren’t replaced in the resultant stored body of the content in the activity eg
This is happening due to an issue in the following create email activity functionality: https://github.com/civicrm/civicrm-core/blob/master/CRM/Contact/Form/Task/EmailCommon.php#L467-L483
This is used:
- When creating an activity from the contact record: This can be done by clicking on the ‘Send email’ action which triggers the form above
- From within a case: The same form is used when creating a ‘Send email’ activity from within a case
Proposed behaviour
The created activity should store (in the content) the "resultant value" of any "tokens" with the content they were actually sent as to the recipient rather than just the {token} field name itself.
Technical implementation suggestions:
-
The email activity is created before the token replacements is done here: https://github.com/civicrm/civicrm-core/blob/master/CRM/Activity/BAO/Activity.php#L1122.
-
Token replacements are done here: https://github.com/civicrm/civicrm-core/blob/master/CRM/Activity/BAO/Activity.php#L1193-L1216
-
Change will be to move the activity creation to just before the email is sent, after token replacements are done to somewhere like here: https://github.com/civicrm/civicrm-core/blob/master/CRM/Activity/BAO/Activity.php#L1227 with the following code:
activityID = self::createEmailActivity(
userID, $tokenSubject, $tokenHtml, $tokenText, $additionalDetails, $campaignId, $attachments);
We have tested this on our local and are happy to submit a core PR if the concept is approved.