views:

363

answers:

2

We want to make it easy for users to send a piece of content (say a Word Document) from an internal SharePoint site to someone else, similar to the "send to friend" feature you see everywhere, but actually sending the content, not just the link.

Is this easily achievable with SharePoint?

The answer "No" from someone reputable is an acceptable answer.

+1  A: 

You can do it using Custom Actions and a Layout page. Refer to this link for further details . Formatting in the link is untidy but that is the method you need to follow. One more thing you might need to do is to somehow sepcify the email Id to send in the above article they are getting the email from user. You might need to send that one as well as querystring parameter.

Kusek
+1  A: 

My firewall is blocking kusek's link but I'm sure that's the place to go. Coincidentally I was just developing this yesterday so can share the highlights.

Feature file

This custom action feature adds a menu option to all document libraries. Adjust the content type if you need to restrict this to only certain documents.

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"&gt;
    <CustomAction
     Id="OpenInMailClient"
     RegistrationType="ContentType"
     RegistrationId="0x0101"
     Location="EditControlBlock"
     Sequence="500"
     ImageUrl="/_layouts/images/iceml.gif"
     Title="Send As Attachment">
     <UrlAction Url="~site/_layouts/Custom/SendMail.aspx?ItemId={ItemId}&amp;ListId={ListId}" />
    </CustomAction>
</Elements>

Application page

I developed an application page used Karine Bosch's excellent reference of SharePoint controls to design and create the application page so it looked nice and 'SharePointy'. I also used a rich HTML box so the user could enter rich text into the body which seems to be working nicely.

Sending the message

This is pretty standard .NET. The only semi-cool part is using the outgoing mail server set in SharePoint to send the message. Note that there is a method to send mail in the SharePoint API but it doesn't seem to support attachments and I couldn't see the benefit of using it.

// Prepare message
MailMessage message = new MailMessage
    {
     Subject = txtSubject.Text,
     Body = txtBody.Text,
     IsBodyHtml = true,
     From = new MailAddress(txtFromAddress.Text)
    };
message.To.Add(txtToAddress.Text);
if (!String.IsNullOrEmpty(txtCCAddress.Text))
    message.CC.Add(txtCCAddress.Text);
message.Bcc.Add(txtBCCAddress.Text);

// Prepare attachment
Stream stream = chosenItem.File.OpenBinaryStream();
Attachment attachment = new Attachment(stream, chosenItem.Name, "application/octet-stream");
message.Attachments.Add(attachment);

// Send message
string server = SPContext.Current.Site.WebApplication.OutboundMailServiceInstance.Server.Address;
SmtpClient client = new SmtpClient(server);
client.Send(message);

// Clean up
stream.Dispose();
attachment.Dispose();
message.Dispose();
Alex Angas