Can any one help me out . How to send an email to Account Owner from contract object in Batch Class.Im using templateid ,in target object im giving the contact id ,in whatid im sending the Account owner email ,but the Account owner is not getting any email.What im doing is correct .Any help very much appreciated.
Portion of Code :
global void execute(Database.BatchableContext bc, List < Contract >
recs) {
List < Messaging.SingleEmailMessage > mailList = new List < Messaging.SingleEmailMessage > ();
for (Contract c: recs) {
if (c.Contact_Email__c != null) {
List < String > toAddresses = new List < String > ();
List < String > CcAddresses = new List < String > ();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//toAddresses.add(c.Contact_Email__c);
ccAddresses.add(c.Account.Owner.Email);
//toAddresses.add(c.Account.Owner.Manager.Email);
// mail.setToAddresses(toAddresses);
mail.setCcAddresses(CcAddresses);
mail.setTargetObjectId('c.contact__r.Id)');
mail.setWhatId(c.Account.Owner.Manager.Email));
mail.setTemplateId('00X4B000000M3go');
mail.setSaveAsActivity(false);
mailList.add(mail);
}
}
Messaging.sendEmail(mailList);
}