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
TexasWheelingTexasWheeling 

Email Service Adding HTML Paragraph Tag to Email Body

I have an email service setup to automatically create records within a custom object that we have setup. The email service parses the email's Subject into the name of the new record, and the email's Body into a "Description" custom field within the new record.

The email service works great, and can parse the email's content perfectly regardless of whether the email is plain text or an html email. However, whenever an html email goes through the email service, it adds the following html tag to the beginning of the "Description" field.

p{margin-top:0px; margin-bottom:0px;}

 Here's the code of the Apex Class I am using for this email service...

 

global class createMatrixRecordFromInboundEmail implements Messaging.InboundEmailHandler {

    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        String myEmailBody = email.HTMLBody;
        IF(String.isNotBlank(myEmailBody)) {
            myEmailBody = email.HTMLBody;
        }
        ELSE {
            myEmailBody = email.plainTextBody;
        }
        List<Matrix_Team__c> mtrList = new List<Matrix_Team__c>();

        Matrix_Team__c mtr = new Matrix_Team__c(RecordTypeId = '012Z00000000WUD', OwnerId = '00GZ00000014KGG', Name = email.Subject, Description__c = myEmailBody);
        mtrList.add(mtr);
        insert mtrList;
        System.debug('New record(s): ' + mtrList);
       
        if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
            for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
                Attachment attachment = new Attachment();
                attachment.ParentId = mtr.Id;
                attachment.Name = email.binaryAttachments[i].filename;
                attachment.Body = email.binaryAttachments[i].body;
                insert attachment;
            }
        }

        result.success = true;

        return result;
    }
}

 

Do you know why the paragraph html tag is being added in whenever an html email goes through my email service?

Thanks!
TexasWheelingTexasWheeling
Any ideas out there? I'm really on a tight time-crunch and need to get this solved quickly. It's stumped me all last week, and I'm not sure where to go from here.
Ido Greenbaum 10Ido Greenbaum 10
@texaswheeling - were you able to find the root cause? 
We are currently experiencing the same issue, where 'p{margin-top:0px; margin-bottom:0px;}' is added to the Email Messages. 

Thank you.