Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a Sharepoint list with incoming email enabled, and an email event receiver to create items out of incoming emails. Once an email is received, it sends an email back to the sender with the contents as a confirmation.

You can send an attachment and the receiver will add the attachment to the list item, but most users paste screenshots into emails instead of attaching saved images (easier).

Is there a way to parse these pasted images and add them to the list item as an attachment?

share|improve this question
    
Aren't they just embedded as <img /> tags? –  RJ Cuthbertson Aug 2 '12 at 18:20
    
Yeah but the src is different, eg: <img width="277" height="588" id="Picture_x0020_1" src="cid:image001.png@01CD708B.77509FF0" alt="Description: cid:image001.png@01CD7089.09DE0C70"> –  cbrad Aug 2 '12 at 18:23
add comment

1 Answer 1

This is probably a good place to start:

http://stackoverflow.com/questions/3691877/regex-to-find-in-line-images-in-a-plain-text-email-message

Once you can decode the image (look at the example return data here: http://stackoverflow.com/questions/4332400/python-parsing-emails-with-embedded-images) then it's a matter of simply adding the image as an attachment.

One of the big issues you're going to run into is making this work with email from all email clients, as different clients use different formatting.

As far as uploading it as an attachment to the list, see this post:

http://stackoverflow.com/questions/1334695/sharepoint-how-to-add-an-attachment-to-a-list-item-programatically

And here's the code snippet:

foreach (FileInfo attachment in attachments)
{
    FileStream fs = new FileStream(attachment.FullName, FileMode.Open, FileAccess.Read);

    byte[] ImageData = new byte[fs.Length];
    fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
    fs.Close();

    item.Attachments.Add(attachment.Name, ImageData); 
}
share|improve this answer
    
Cheers, should have checked there first, more of a general outlook thing. I'm not too concerned about other email clients as it's an internal site and we only use outlook here. I may have to modify it for the outlook web app depending if it formats things differently. –  cbrad Aug 2 '12 at 18:28
    
No problem, glad to help. –  RJ Cuthbertson Aug 2 '12 at 18:59
    
Asked a more specific question, posted here: stackoverflow.com/questions/11784013/… –  cbrad Aug 2 '12 at 19:00
    
Personally, I would break off the SharePoint portions of that other question. You might get barked at for that. SO is a good place to ask about email parsing. This is a good place to ask about SharePoint. I'm going to edit my answer here to include a code sample to upload an attachment to a list item. –  RJ Cuthbertson Aug 2 '12 at 19:15
    
Still having problems with this... Not sure how to go about it. –  cbrad Aug 14 '12 at 21:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.