Skip to main content

Cloud

Email Document Library item as Attachment

I recently worked on a requirement where the client wanted the functionality of sending an item in document library as an attachment. If you look at the OOTB drop down menu of a document library item, it will give you the option to E-mail the link to the document but not to send the document itself as attachment. My client wanted this functionality from the same drop down menu. Like any developer, I started by searching the web hoping that it might be implemented already and save my self from re-inventing the wheel. I came across this great article by Becky Bertram which does exactly the same thing. She used an application page to implement this but unfortunately this is not going to work in my case. I needed a solution where Outlook mail message should open with attachment on click of a link in the drop down menu. This can be achieved using the feature route Becky has explained but we will add javascript to send the attachment instead of the application page.

Let’s look at the steps now. You first need to create a folder for the feature in 12TemplateFeatures. You need to create the feature.xml like this:

<Feature xmlns="http://schemas.microsoft.com/sharepoint/"

Id="f07a7415-abcc-4824-9b94-6b09e17dd7b8"

Title="Email Document as attachment"

Scope="Web" Hidden="false" Version="1.0.0.0"

Description="This feature allows you to E-mail documents from your Document Libraries">

<ElementManifests>

<ElementManifest Location="elements.xml"/>

</ElementManifests>

</Feature>

You might have to change the GUID of the ID. Element manifest file will have the functionality to add the attachment option to the document library item menu and also the javascript to implement it. Create "Elements.xml" in the same folder with the below XML:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<CustomAction

Id="MailDocument.Link"

RegistrationType="List"

RegistrationId="101"

Location="EditControlBlock"

Sequence="350"

Title="E-mail as Attachment"

ImageUrl="~site/_layouts/IMAGES/EML16.GIF"

Description="Allows a user to e-mail a document in a document library to themselves." >

<UrlAction

Url="javascript:function emailDocument(documentUrl)

{

try

{

var protocolsplit = location.href.split(‘//’);

var urlsplit = protocolsplit[1].split(‘/’);

var fileUrl = ‘http://’ + urlsplit[0] + documentUrl;

var outlook = new ActiveXObject(‘Outlook.Application’);

var outlookMessage = outlook.CreateItem(0);

var outlookAttachment = null;

outlookAttachment = outlookMessage.Attachments.Add(fileUrl);

outlookMessage.Display();

outlookAttachment = null;

outlookMessage = null;

outlook = null;

}

catch(e)

{

alert(‘Please check the following: 1. Microsoft Outlook is installed. 2. In IE the SharePoint Site is trusted. 3. In IE the setting for Initialize and Script ActiveX controls not marked as safe is Enabled in the Trusted zone.’);

}

}; emailDocument(currentItemFileUrl);"/>

</CustomAction>

</Elements>

Now you know what to do: install and activate the feature. After activating the feature, your document library menu item should like below:

As you can see in the catch block, you should be ready to lower the IE settings to make it work.

Thoughts on “Email Document Library item as Attachment”

  1. Hi Raja,
    can we do it the same in “version history”. same as we get “email as attachment” what i meant to say is after clicking on version history this option to be displayed. already we have “view”, “restore” and “delete” like this we need one more called “email as attachment”.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Raja Ayyapusetty

Raja is a software consultant with over 9 years of experience in designing, developing and testing complex solutions using Microsoft technologies. Throughout his career he has worked primarily on SharePoint and .NET technologies. Raja has worked with SharePoint since the 2003 version and has deep understanding of its features and capabilities. Raja is also a certified Sitecore developer.

More from this Author

Follow Us