6

SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Invalid to address : : [] Error is in expression '{!sendEmail}' in component in page MyPage: Class.MyClass.sendEmail: line 408, column 1

Send Email code is as below

Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.saveAsActivity = false;
message.setOrgWideEmailAddressId(emailFromAddress);//emailFromAddress(string)-containing id
message.setCcAddresses(new String[]{emailCCAddress});//emailCCAddress(string)
message.setBccAddresses(new String[]{emailBCCAddress});//emailBCCAddress(string)
message.setSubject(emailSubject);//emailSubject(string)
message.setHtmlBody(emailBody);  //emailBody(string)
message.setToAddresses(new String[]{emailToAddress.trim()}); //emailToAddress is a string containing 'abc@abc.com'
//message.setToAddresses(new String[]{'abc@abc.com'}); //Tried this too still giving same error
Messaging.SendEmailResult[] mailResults = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{message});// Line 408 where error occurs

Please help! i am facing this issue since long time. Tia

12

Try validating cc and bcc addressess by checking null or empty

  if(emailCCAddress != null && emailCCAddress.trim() != ''){
        Ccaddress = emailCCAddress.split(',',0);
        mail.setCcAddresses(ccaddress);
        }
  if(emailBCCAddress != null && emailBCCAddress.trim() != ''){
        Bccaddress = emailBCCAddress.split(',',0);
        mail.setBccAddresses(Bccaddress);
        }
| improve this answer | |
0

I would start by debugging this line, as it is likely causing the issue:

system.debug('EMAIL IS ' + new String[]{emailToAddress.trim()});

Then you can see if that is just not a valid email before you start to get crazy, most of the time it is something dumb that is holding you up, it is possible the value of 'emailToAddress' is not what you are expecting.

| improve this answer | |
  • That was my first step of solving issue. It had shown a valid email address. Anyways thanks for your help. My BCC address had issue so Animesh answer worked well for me :) – snehakem Jan 22 '15 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.