none
SPUtility.SendEmail not working RRS feed

  • Question

  • If I run this exact line of code in a sharepoint project located in the sharepoint server (_layouts/projectname), everything works fine, so I know the email server is working properly.  Its only when I create a project outside sharepoint is when this error occurs.

     

    SPUtility.SendEmail(myWeb, false, false, "test@test.com", "Title", "Body');

    An error message of "Object reference not set ot an instance of an object" is returned.  I thought perhaps is a priviledge issue so I wrapped the line of code with:

     

    SPSecurity.RunWithElevatedPriviledges(delegate()

    {

    SPUtility.SendEmail(myWeb, false, false, "test@test.com", "Title", "Body');

    });

     

    An error message of "Operation is not valid due to the current state of the object" appears.  I even tried passing an SPUserToken of the site administrator when referencing the site and it still gives the same error.

     

    In case you are wondering, here is how myWeb is defined:

    SPSite mySite = new SPSite('http://sharepointsite', token); //with or without token doesn't work

    SPSite myWeb = mySite.RootWeb

     

    Any help is greatly appreciated.

     

    -Tony

    Wednesday, May 28, 2008 6:07 PM

Answers


  • Hi,


    You have mentioned that, this code will not work outside. SharePoint object model run only in SharePoint server, we cannot execute the code in client machines.


    If I misunderstood your question, explain me in detail.


    Wednesday, May 28, 2008 7:09 PM