+ Start a Discussion
darhdarh 

debugging inbound email handling

As I just spent days debugging my inbound email application, I thought I'd share my hard-to-find mistakes in case they're not unique to me.

My implementation of Messaging.InboundEmailHandler worked just fine when I sent test emails from Outlook. Nothing happened when I sent emails via PHP's mail function. It appeared as if the email never even arrived.

My first mistake was not setting the Return-Path in PHP. Salesforce was generating email error messages, I just never got them.

The second error was an off-by-one count when parsing the email strings. I'm fairly sure that Outlook appends a \r\n (carriage return and a line feed), where the PHP code was only appending a \n. I never saw the System.StringException (which I wasn't testing for, either!) until I fixed the Return-Path problem.

Code & learn!
JimRaeJimRae
One other hint, from my experience.  If you want to really see what is going on, you can use the Monitoring Debug Logs to see what happens when your code executes.  You will need to set some system.debug statements to see the details, but you can go to Setup, Monitoring, Debug Logs and then add a monitor for the running user of your inbound email class.  when you send a test message in, you can look at the log list, and you will see the debug log output.
This is very helpful to see what is really going on when a live message is passed in (as opposed to a testmethod message).