function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sekharasekhara 

Help on E mail template

HI

i am getting problem went i am sending e mail directly by using onclick function , 

I wrote Apex class for that . But i am getting error as " Email could not be sent. Email address may not be set or may be invalid ".

 

I am posting my controller here ,

 

global class SendAccountAsEmail
{
   
    static String SUBJECT = 'Prospect- Counselling Note';
    static String ERROR_MSG = 'Error Sending Email.<br/>Check validity of email addresses.';
    static String SUCCESS_MSG = 'Mail Successfully Sent.<br/>You can close the window.';
     
     webservice static String sendMail(Id recordId)
     {   
        Blob pdfAttachment;
        String Content_To_Send;         
        Account controller = [Select id,name,Last_Purchaser_Email__c from account where Id = :recordId];
        Content_To_Send= 'Please Find Attached Counselling Note For '+controller.ID +' ' +controller.Name;
        try
        {
      
            
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            List<Messaging.EmailFileAttachment> attachList = new List<Messaging.EmailFileAttachment>();
            if(!Test.isRunningTest())
            {
                Messaging.EmailFileAttachment attachPdf = new Messaging.EmailFileAttachment();
                attachPdf.setBody(pdfAttachment);    
                attachPdf.setFileName('test.pdf');
                attachList.add(attachPdf);
                mail.setFileAttachments(attachList);  
            } 
         
             List<String> toAddresses = new List<String>();
           
                toAddresses.add('swathibhouni@gmail.com') 
            mail.setToAddresses(toAddresses);
            mail.setSubject(SUBJECT);
            mail.setHtmlBody(Content_To_Send);
            mail.setSenderDisplayName('Salesforce Support');
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            return '1';
        }
        catch(Exception e)
        {
            System.Debug('Exception : ' + e.getMessage());
            return '0';
        }
    }
}
Can any one help on this issue .

Thanks in advance ..