[SalesForce] Track Email Status (Opened or Not) sent from apex code

I already read some similar posts related to this topic.
But I think things may have changed or the answer may be different.

I know we can track email status if we send HTML email from the Contact related list using "Send an Email button".

So can we initiate this from apex code? Just like we can initiate the approval process from apex code?

Best Answer

You can - just ran this test for myself in a Dev org:

trigger SendAction on Contact (before insert, before update) {
    for (Contact c : Trigger.new)
    {
        if (c.Action__c == 'Send HTML Email' && c.Email == 'test@example.com')
        {
            c.Action__c = '';
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setTargetObjectId(c.Id);
            email.setTemplateId('00X70000001vqKB');
            Messaging.sendEmail(new Messaging.Email[] { email });
        }
    } 
}