Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have created a email service to receive a emil from a provided email id I want to print the emiail body in debug log for this I write some debug to that but my problem is nothing get printes in debug log so will you please suggest me how to print email body in debug log.

My email service class code -

global class ProcessCaseEmail implements Messaging.InboundEmailHandler
{
    ProcessCaseEmail ()
    {
        System.debug('=======');
    }

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

        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        String myPlainText= '';
        myPlainText = email.plainTextBody;
        System.debug('Plain text+++++++++++' + myPlainText );
        List<String> parts = myPlainText.split('\n');

        List<String> columns;
        for(integer i=0;i<parts.size();i++)
        {

            System.debug('Parts+++++     ['+i+']   '+parts[i] );
            system.debug('Length of the parts ['+i+']  '+parts[i].length());

        }
        return result;
    }
  }
share|improve this question
    
Have you turned on debug logging for the context user of the email service? –  Bob Buzzard Jan 16 '13 at 8:20
    
can you please elaborate more. –  D-Horse Jan 16 '13 at 11:16
    
The answer below covers this. –  Bob Buzzard Jan 16 '13 at 11:25

2 Answers 2

You are only printing the plain text body, perhaps you are sending your email as HTML?

this works perfectly for me:

global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope)
    {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

        System.debug('HTML BODY: '+email.htmlBody);
        System.debug('TEXT BODY: '+email.plainTextBody);
        System.debug('SUBJECT: '+email.subject);

        return result;
    }

Do make sure you put on debug logging for it to work, go to:

  • Setup
  • Administration Setup
  • Montitoring
  • Debug Logs
  • Add a New monitored user (make sure you choose the user you setup for handling your inbound email)

Send your mail, refresh the page, there should now be logs available:

Log Overview Log

share|improve this answer

Or if you are the context user - you can just monitor the logs in the Developer Console as they occur.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.