How to send an e-mail with attachment from SharePointOctober 2, 2007 11:52
To be able to send attachment I decided to make use of the normal “System.Net.Mail” classes to send a message. Instead of hard coding the SMTP information into the code, I wanted to use the SMTP settings that are configured with the SharePoint Central Administration. These settings are found in the “SPAdministrationWebApplication” class. Because SharePoint stores it’s files into the content database, we must do a http request to retrieve the attachment. Using the “System.Net.WebClient” is one way to do it and one of the advantages is that you can supply it with the credentials of the user that is trying to send the mail. You will receive an unauthorized message if you don’t supply a correct set of credentials. It’s probably not a good idea to hardcode the credentials as it will be possible for users to get access to files they are not supposed to. Supplying the WebClient with the “CredentialCache.DefaultNetworkCredentials” worked fine for me on a standard SharePoint environment. Below is a brief example on how you can send the mail with attachment from code. If you prefer to use the user’s e-mail address instead of the configured SMTP user you can retrieve it with SPControl.GetContextWeb(Context).CurrentUser.Email. Tags: central administration, content database, credentials, email, SharePoint, smtp settings, webclient.Two custom development examples build for SharePoint 2007September 30, 2007 19:26SharePoint provides a lot of functionality out of the box, but of course there are always parts that have to be custom build. In this post I will show you 2 cool examples of what is possible with SharePoint when you add some custom development. Last week I’ve developed these two custom parts at Macaw to extend the functionality of the document library. File preview Send a file attachment by e-mail It requires custom development to send an e-mail with the file attached. To make SharePoint email the file we have used a SharePoint feature to add a new menu option to the item menu that presents the user with an e-mail page. After filling in the form SharePoints sends out the message with the selected file as attachment. Of course you can see a demo of it in another Flash movie. [UPDATE 12-11-2007] |
||