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 '[email protected]'
//message.setToAddresses(new String[]{'[email protected]'}); //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

2 Answers 2

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);
        }
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.

1
  • 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
    Commented Jan 22, 2015 at 6:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .