[SalesForce] Gmail Forwarding Address verification code for Apex Email Service

I have written an Apex Email Service and would like to setup a rule in gmail to forward certain messages to the Email Service.

The first step when creating a forwarding address in gmail is the address first needs to be verified. This is accomplished by requesting a verification code which is sent to the address.

My question is how do I get this email so I can access the verification code?

I have enabled error routing so that failures are sent to me. I have modified the email service to always return a failure, and when I send an email to the service directly I get the failure message. But I request the verification code through google and receive nothing.

I have Accept Email From: mydomain.com, gmail.com, google.com, which may be excessive, because I sent a forward request to a colleague to inspect the email and it originates from mydomain.com

Best Answer

Wow debugging email services is hard! After alot of trial and error I was able to solve my problem.

Thanks for the suggestions @techtrekker and @Abhinav but placing a system.debug in the service did not help as the class was not being called.

The reason for this was the 'Accept Email From' needs to contain the domain of the original sender. For example chatty@salesforce.com sends me an email and my gmail rule forwards it to the email service 'Accept Email From' must contain the salesforce.com domain for the email to be processed.

Additionally, after a bit more testing it appears the 'Accept Email From' does not require mydomain.com

Edit: As suggested by @tanuj leaving 'Accept Email From' blank means all emails are processed, which makes getting the verification code is easier.