Home > .Net, sharepoint > SPUtility.SendEmail

SPUtility.SendEmail

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.

  1. Saurabh Jain
    June 9th, 2008 at 09:18 | #1

    hi i have used this code but html tags is not working . please help

  2. June 9th, 2008 at 09:38 | #2

    Hi Jain,

    Where you are using HTML tags? in message body? And how you come to know it is not working? I got the same issue, but it was the problem of the Outlook, try changing the mail display format.

    Anuraj

  3. morten
    March 25th, 2009 at 09:59 | #3

    Hi anuraj!
    My problem is that the SPUtility.SendEmail returns false and I don’t know how I can check why it is not sending anything. I have also tried to send mail using System.NET.Mail, and it also fails.

    Any suggestions ?

    Morten

  4. May 13th, 2009 at 08:54 | #4

    How to I change or set the display name of an e-mail send with the SPUtility.sendEmail ?

    I am looking for the receiver to get a mail with Frederik [f@k2c.dk] in the FROM field…

    Any suggestions?

    / Frederik

  5. May 14th, 2009 at 13:42 | #5

    Sorry Frederik. I don’t think we can do it. [:(]

  6. jafar
    May 24th, 2009 at 09:58 | #6

    I have almost the same problem SpUtility.SendEmail
    return True but the email is not sent and i could not find any thing in the Applog note I am using SpUtility.SendEmail from SPTimerJob

  7. Janey Wang
    July 20th, 2009 at 14:40 | #7

    Hoi , I think you might be able to do it. Please check http://www.myfatblog.co.uk/?p=79, I have tried it in my project and it works. :)

  8. September 14th, 2009 at 12:20 | #8

    You should check SharePoint logs at information level to find out if there are messages that may lead you to source of your problem.

  9. September 15th, 2009 at 01:41 | #9

    Thanks Gunnar, thanks for the valuable information.

  1. No trackbacks yet.