[SalesForce] Email attachment not received in EmailService handler

I have an issue with processing inbound emails sent from MS Outlook. To put it simple no attachments are received in the class (nor text nor binary). Email definitely has attachments since i cc-ed the email to my gmail account.

If the email with attachment is sent from the gmail account everything works well.

Any thoughts or experiences?

the code:

global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env) 
    {
        System.debug(email);//no attachments all attachment binary and text are null
....}

I think this source could be more important:

Gmail source:

Content-Type: text/csv; charset=UTF-8; name="Karol_csv_short.csv"  
Content-Disposition: attachment; filename="Karol_csv_short.csv"  
Content-Transfer-Encoding: base64
X-Attachment-Id: f_hytz9oxg0

Outlook source

Content-Type: application/vnd.ms-excel; name="Karol_csv_short.csv"
Content-Disposition: attachment; filename="Karol_csv_short.csv"
Content-Transfer-Encoding: base64
X-Attachment-Id: 1cad76b11d272e29_0.1

So the issue could be that the application/vnd.ms-excel content type is not understood by salesforce?

Thanks

Best Answer

I just managed to do a workaround this issue...

I managed to found a way for inbound service to receive the attachments sent from MS Outlook. It seems that SFDC email service under the hood has a limited scope of Content-Type: headers it handles. If the .csv file is attached from Outlook it adds the header value not understood by salesforce Content-Type: application/vnd.ms-excel the attachment is then dropped by SFDC and it never reaches Messaging.InboundEmailHandler implementation.

First I'd like to stress out that this behavior presented by SFDC is invalid and that they should treat all unknown Content-Type: values as application/octet-stream and push them to InboundEmail.BinaryAttachment[] binaryAttachments property.

Then i tried to change the extension of the file to none, attach it in Outlook and see what will happen. Nothing did - again SFDC dropped the attachment which brings me to conclude that SF does not handle application/octet-stream at all.

Take three - I changed the extension of the file to plain old .txt and did the attach/send drill again and it worked. Content-Type: was set to text/plain; charset=UTF-8; by Outlook and SFDC understood it properly adding the file to the InboundEmail.TextAttachment[] textAttachments property.

So to highlight the resolution if somebody finds him/her self in this quite weird situation:

Just change the extension of the file to .txt if it is a .csv file you're trying to push to salesforce from Outlook

Related Topic