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
NitishMishraNitishMishra 

Apex Email Service Attachment content type issue

Hi Everyone, 

 

I am using Inbound email processing to insert an attachment in salesforce. When we send email from our mail box to salesforce email It gets attached and we can read that pdf attachment as well. But When SAP sends email with pdf attachment It gets attached properly to targeted record. But we can't read that atttachment. When same email is sent from SAP to our mail box we get a pdf attachment and read it as well.

 

I used debug to check the content type of attachment It shows :: |[163]|DEBUG|****Content type of attachmnet received *****message/rfc822

But the same attachment received to our mail box from SAP shows :: application/pdf    content type.

 

If any one have any idea to fix this issue that will be great help for me.

Any idea to resolve this issue will be appreciated. Please Help 


Below is the code , its standard salesforce code for apex email service ::


if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
Attachment attachment = new Attachment();
// attach to the Conversation record
attachment.ParentId = newOpp.Id;
if(!email.binaryAttachments[i].filename.endsWith('.eml')){ // Validation check to avoid .eml extension that will not allow email body content to insert as an attachment

System.debug('*****email.binaryAttachments[i].filename***2**'+email.binaryAttachments[i].filename);
attachment.Name = email.binaryAttachments[i].filename;
attachment.Body = email.binaryAttachments[i].body;

System.debug('****Content type of attachmnet received *****'+email.binaryAttachments[i].mimeTypeSubType);
attachment.ContentType = 'application/pdf';
//attachment.ContentType = email.binaryAttachments[i].mimeTypeSubType;
insert attachment;
}
}
}

 

Thanks,

Nitish