+ Start a Discussion
LoneStar69LoneStar69 

Inbound Mail Handler Undeliverable email

Hi,

I am trying to check the incoming mail for a specific id, which will then send an email whether the id is found or not.

No errors in class.
Class -

global class ProcessIncomingEmail implements Messaging.InboundEmailHandler {
      global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
          Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
          
          String mySubject = email.subject;
      String myReply = email.fromAddress;
                   
          Id s = '35987239';
          Boolean b;
              b = mySubject.contains(s);
          List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
          if (b == true) {
              try{
              Messaging.SingleEmailMessage successmail = new Messaging.SingleEmailMessage();
              successmail.setReplyTo('myReply');
              successmail.setSenderDisplayName('Verification Update');
              successmail.setSubject('Your Id is found:');
              mails.add(successmail);
              Messaging.sendEmail(mails);
          }
          
          catch (System.QueryException e){
              System.debug('The issue is: ' + e);
          }
          }
    
          else    {
              Messaging.SingleEmailMessage failmail = new Messaging.SingleEmailMessage();
              failmail.setReplyTo('test@sample.com');
              failmail.setSenderDisplayName('Verification Update');
              failmail.setSubject('Your Id is not found:');
              mails.add(failmail);
              Messaging.sendEmail(mails);
          }
      result.success = true;
          return result;
  }
}

But gives the below error when i try to send email to the Email Service Address.
Error -

This message was created automatically by the mail system.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

>>> idverification@blah_blah_blah.cs33.apex.sandbox.salesforce.com (Undelivered):
554 The apex class ProcessIncomingEmail failed due to: System.StringException: Invalid id: 35987239

Thanks for your help!!!
Best Answer chosen by LoneStar69
ManojjenaManojjena
Hey Id in salesforce always should eith 15 or 18 digit ,Error is basically throwing from that line .
 

All Answers

ManojjenaManojjena
Hi Mairuz,
Can you tell me one thing the id you have declared is for what 
 Id s = '35987239';
Error is coming from that only .

Please clarify .
LoneStar69LoneStar69
Hi Manoj,

It's just a random Id i want to check in the incoming email subject.

 
ManojjenaManojjena
Hey Id in salesforce always should eith 15 or 18 digit ,Error is basically throwing from that line .
 
This was selected as the best answer
LoneStar69LoneStar69
Now it says,

(Undelivered): 554 The apex class ProcessIncomingEmail failed due to: System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing target address (target, to, cc, bcc): []
LoneStar69LoneStar69
Made use of https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_single.htm