Archive

Posts Tagged ‘SPUtility’

SPUtility.SendEmail

November 7th, 2007 Anuraj P 9 comments

In my project I need to send mail to Administrator, while adding items to a list using Webpart. I have tried ASP.Net, System.Net namespace but I need to read all the server and mail settings from any config file. After I got sharepoint’s own mechanism to send mail.

SPUtility.SendEmail(SPContext.Current.Site.OpenWeb(), false, false, "admin@myserver.com", "Hello World", "This is a Sample Mail");

This will send a mail to “admin@myserver.com”, with “Hello World” as subject and “This is a Sample Mail” as body. You can send HTML emails by changing the third parameter to TRUE.

Update : You may need to use SPSecurity.RunWithElevatedPrivileges method to send mails.

Url :

http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

This method enable users to Execute the specified method with Full Control rights even if the user does not otherwise have Full Control.