I'm working on a trigger that sends an e-mail to a contact when his e-mail address is updated. The e-mail has an HTML template (so a target object id must be specified). The problem is; we also want to send an e-mail to the previous address. Is there a way to accomplish this using two e-mails (we don't want the e-mail to the old address to show the new one and vice-versa).
The code I'm using at the moment is:
if (newContact.Email != oldContact.Email){
List<Messaging.SingleEmailMessage> messages = new List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.setTemplateId(emailTemplateId);
message.setTargetObjectId(newContact.Id);
//this line adds the old e-mail to the recipients, but this is visible to the other
//message.setToAddresses(new String[] {oldContact.Email});
message.setSenderDisplayName('I love hats');
message.setReplyTo('[email protected]');
messages.add(message);
List<Messaging.SendEmailResult> ser = Messaging.sendEmail(messages);
}