+ Start a Discussion
PS81PS81 

Mail not received - SingleEmailMessage

Hi 

I'm trying to send mails to the owners of the Campaigns on certain conditions using SingleEmailMessage. While i could see no error in debug the mails seems not being recieved @ my inbox. Below the code snippet....any inputs to correct this or troubleshoot please?

    public static void sendMail(List<Campaign> Campaigns){
        for(Campaign camp:campaigns){
            //New instance of a single email message
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            // Recipient
            mail.setTargetObjectId(camp.CreatedById);
            // Set the mail template
            mail.setTemplateId('00X26000000DbPe');
            mail.setBccSender(false);
            mail.setUseSignature(false);
            mail.setSaveAsActivity(false);
            //mail.setWhatid(camp.Id);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }
    }
Best Answer chosen by PS81
Andrew EchevarriaAndrew Echevarria
Try changing recipient from mail.setTargetObjectId(camp.CreatedById); to mail.setTargetObjectId(camp.Owner);

All Answers

PS81PS81
Nb: I'm trying to trigger the mail by testing it using the annotation @isTest for the class...
Andrew EchevarriaAndrew Echevarria
Try changing recipient from mail.setTargetObjectId(camp.CreatedById); to mail.setTargetObjectId(camp.Owner);
This was selected as the best answer
PS81PS81
Thans Andrew. Realised the class is set as test.