When sending an email using a template in Apex, the “targetObjectId” is typically required, which must be the ID of a Lead, Contact, or User. However, in many cases, you may not have a targetObjectId available, especially when sending an email from a custom object to an external email address that isn’t associated with a Lead, Contact, or User in Salesforce.
Many articles suggest creating a dummy Contact record to use as the targetObjectId, but this workaround can be cumbersome and unreliable.
Here’s a more effective solution that avoids the need for a dummy Contact. See the sample code in article.