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
NazeerNazeer 

Inbound email attachments

Hi,

How do we handle the attachments in inbound mail? I need to capture email attachment as attachment in Salesforce.  I had created Salesforce (case) records from the contents of email but struggling to handle attachment. Any detail update on this is highly appreciated.

How we can handle this through Apex EMAIL SERVICES
 
Thanks
Nazeer

Message Edited by Nazeer on 11-23-2007 07:35 AM

Rasmus MenckeRasmus Mencke
Nazeer,

Here is an example of how you can loop through an inbound email and find all the attachments. In this case I create an attachment and link it to an emailMessage object I have created previously in the Apex code.


.....

if (email.binaryAttachments!=null && email.binaryAttachments.size() > 0) {
            for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {

System.debug('Binary Attachments - filename: ' + email.binaryAttachments[i].filename);
System.debug('Binary Attachments - size: ' +   email.binaryAttachments[i].mimeTypeSubType);
           
            Attachment a = new Attachment(ParentId = em[0].Id,
                                          Name = email.binaryAttachments[i].filename,
                                          Body = email.binaryAttachments[i].body);
            insert a;
            }
    }


...........
DavidDDavidD
HI Rasmus,

Your post is really helpful, we are currently testing the email services and experiencing some problems with the attachments,

Let's me clarify what we are doing.

1. we have received a lot of emails in outlook . say 5 thousands emails.
2. we want to forward these emails to Salesforce email service, each time we are going to forward 10-50 emails to salesforce
3. these forwarded emails become binary attachments, so we need to process these attachemnts in Salesforce email service.
4. With our emails service, let's call it processAttachment, we want to parse each attachment, as each one originally is an email.

Yes, we can loop through all the attachements, .to figure out filename, size, mimeTypeSubType (message/rfc822) .etc.
however we don't know how to convert each attachment into an inboundEmail object, so we can create task for each attachment?

We would really appreciate it if someone can help us with this?

Thanks a lot in advance!

Best Regards,

David Deng



PamSalesforcePamSalesforce

Hi David,

 

Can you please post the code for this? 

 

Thanks,

Daniel GrabowskiDaniel Grabowski
Hi DavidD,

Did you ever figure out a solution to this?  I'll keep digging but trying to solve this issue currently.

Thanks,
Daniel