function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
zaidyzaidy 

Inbound Email email.plainTextBody does not recognizes '\n'

Hi, 

I have implemented a class which received an email with similar to:

 

Subject: RE:APPL001

Approved

The second Line

 

As you can see the body has two lines: 

1st Line : Approved

2nd Line: The second Line

 

My class is as follows: 

 

 

global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env)
    {
        // Indicates if the message processes successfully, permits an error response to be send back to the user 
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        try
        {

 

global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env)    {        

Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();        
try        {
	System.debug('plainTextBody: ' + email.plainTextBody);
	String[] emailBodyArray = email.plainTextBody.split('\n', 0);
	System.debug('emailBodyArray[0]: ' + emailBodyArray[0]);
	if(emailBodyArray[1]!=null && emailBodyArray[1]!=''){
				comment = emailBodyArray[1];
				System.debug('ApprovalInb comment : ' + comment);
	}
catch (Exception e)
        {
            // Return an email message to the user
            result.success = false;
	}
}

 

 

}

 

When I send the above email, the logs show me: 

15:10:12.670|USER_DEBUG|[20,13]|DEBUG|plainTextBody: ApprovedThe second Line

 

As you can see above, the value of email.plainTextBody hasn't respected the return character between the two lines and has added both lines into one line only, therefore I am not able to process the body into an array with two items. 

Any one know why? 

 

Best Answer chosen by Admin (Salesforce Developers) 
zaidyzaidy

I have no idea but email.plainTextBody started working properly this morning.I have not changed the code or any settings, and it is working now.

Thanks anyway for your information.

All Answers

gbarger4581gbarger4581

Have you tried actually having a message sent to you instead of just the debug log. I create a message body in a string before sending several messages out, and I use this in a for loop to create a list of records that haven't been approved in more than 30 days. The email body does come out correctly for me.

body+= server+'salesforce.com/'+objid+'\n'
zaidyzaidy

I have no idea but email.plainTextBody started working properly this morning.I have not changed the code or any settings, and it is working now.

Thanks anyway for your information.

This was selected as the best answer
zaidyzaidy

email.plainTextBody does not recognizes '\n' has come back after Summer10 release.

 

Kameswari T PadmanabanKameswari T Padmanaban
We face similar issue for few users in spring 15. Can someone provide some suggestions here? Is this related to email setting?