Minor trip up today
I set up an Inbound Email Service in PROD. Email address (friendly) was foo@bar.com
. “bar.com” uses Gmail as corporate email system. As you know, you need to forward the emails received at fooo@bar.com
to foo@verylongemailaddress.pod.apex.salesforce.com
.
When the forwarding is done by Gmail, it sends a confirmation code requesting verification of the forwarding before Gmail will enable.
Where do you see this confirmation code?
There’s no mailbox to look at in Salesforce. So, what I did was code a super class for my Inbound Email Handler class that had a method log(..)
:
public virtual void log(Messaging.inboundEmail email,Messaging.InboundEnvelope env) { System.debug(LoggingLevel.INFO,'\n INboundEmail Envelope:\n' + 'from:' + env.fromAddress + ' to: ' + env.toAddress + '\n' + '\n subject :' + email.subject + '\n ccAddresses:' + email.ccAddresses + '\n toAddresses:' + email.toAddresses + '\n fromAddress:' + email.fromAddress + '\n fromName :' + email.fromName + '\n headers :' + '\n' + headersToString(email.headers) + '\n #binAtch:' + (email.binaryAttachments != null ? email.binaryAttachments.size() : 0) + '\n #textAtch:' + (email.textAttachments != null ? email.textAttachments.size() : 0) + '\n plaintextBody:' + email.plainTextBody + '\n htmlBody:' + email.htmlBody );
I invoked this method in the InboundEmailHandler (called Email2Lead in this use case) so every message would be logged
public Email2Lead() { super(); } public Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,Messaging.InboundEnvelope env) { Messaging.InboundEmailResult res = new Messaging.InboundEmailResult(); log(email,env); ... do work here .. res.success = true; return res; }
So, turn on debug log for the context user of the Inbound Email Service, use Gmail to send the confirmation request of the forwarding rule, and then inspect your debug log in the value of the plaintextbody
debug line
What if you don’t get the confirmation code?
The most likely reason is that your Inbound Email Service is configured to only accept emails from certain domains. This list of domains needs to include google.com as that is the source of the confirmation code for the forwarding rule. The source is not your corporate mail system (e.g. bar.com)