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.

1 Answer 1


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 [email protected].

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
    Commented Jun 18, 2018 at 5:49
  • Updated the answer. Hope it helps!
    – Sam
    Commented Jun 18, 2018 at 6:12
  • 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
    Commented Jun 18, 2018 at 6:40
  • 1
    @Anamadeya this is really cool. Is it (option1) documented anywhere on the developer site or you figured out that by yourself?
    – zuke
    Commented Jun 24, 2018 at 23:49
  • 1
    @zuke : Fortunately, I was able to figure it out on my own :)
    – Sam
    Commented Jun 25, 2018 at 0:30

You must log in to answer this question.

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