2

I'm leveraging 'Send an Email' button for a custom object(comm__c) which has a lookup to the case object. While sending the email the user sets the 'From email address' to a specific Organization-Wide Email Address.

I'm creating a comm__c record every time an outbound email is sent by leveraging EmailMessage object, now my requirement is to create a comm__c record for each inbound email replied to the Organization-Wide Email Address.

If I write a class implementing InboundEmailHandler interface and setup an Email Service the setup process doesn't ask me to specify the Organization-Wide Email Address in any of the steps. Please advise.

6
+50

2 options:

Option 1

1) Create a class which implements the inboundHandler.

global class VerifyOrgWideEmailAddress implements Messaging.InboundEmailHandler {

    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();


        //This is one time thing that you will have to perfrom everytime you setup the org wide email address.
        //Use this html body to fetch the verification link and open it in a browser to verify it. 
        System.debug('The email Body ==> '+ email.plainTextBody);

        result.success = true;
        return result;
    }
}

2) Create a email service and link the above class that you just created. 3) Create a new email address under the Email Services.

4) Copy the email address that you just created and use it to create the Org Wide Email address.

5) Open the developer console and wait for a log with the Operation , 'EmailToApexHandler'. Open the log and search for the verification Link keyword.

enter image description here

6) Copy-paste the verification link in browser and that should be it.

7) Now, you would need to update the email services class to handle your custom logic.

Option 2.

1) Say you have setup an org email address which is pointing to support@gmail.com.

2) Create an email service.

3) You will have to setup an email forwarding in the email server (for this example the email forwarding will be setup in gmail) to forward all the email to the email services email that you have created.

  • Please elaborate option 1 step 3) , to get the verification link do I have to write an inbound email handler? Inbound handler is for parsing the email contents how can I write the code within to get the verification link? – Jarvis Jun 18 '18 at 5:49
  • Updated the answer. Hope it helps! – Sam Jun 18 '18 at 6:12
  • Do I have put a debug log on the above class and then send a test email to the email service address ? I'm confused. – Jarvis Jun 18 '18 at 6:22
  • 1
    So, first you have to create the class and the add that class in the email service. Then you need to create an email address for the email service that you just created. Now, keep the developer console open to view logs. Post that go to the Org Wide Email address and add the email address that you created under the email service and save it.. This would have triggered a verification email. Now you need to go back to the dev console and there would be a log with the Operation 'EmailToApexHandler', open that log and click open the verification link. – Sam Jun 18 '18 at 6:40
  • Are you sure just creating or updating the OrgWideEmail address will show up the verification link in the debug log ? Or do I have to email to the email generated as an additional step ? – Jarvis Jun 18 '18 at 7:37

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.