Note that, Only User, Contact, Lead, or Person objects are allowed for targetObjectId and it is mandatory.
Ideally, if you want to send an email to Contact then put ContactId
as targetObjectId
So, if you don't like to put Contact then use UserId
as targetObjectId
.
Moreover, if you have activity on Contact it will also be reflected under Account.
Following code save the email under ActivityHistory of Case, Contact and Account.
List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage theMessage = new Messaging.SingleEmailMessage();
theMessage.setTemplateId(emailTemplateId);
theMessage.setTargetObjectId(this.myCase.ContactId);
List<String> toAddress = new List<String>();
toAddress.add(this.myCase.Contact.Email);
theMessage.setToAddresses(toAddress);
theMessage.setWhatId(this.myCase.Id);
theMessage.setSaveAsActivity(true);
messages.add(theMessage);
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);