Ok, so I am no an administrator so i cannot just remote into the box and grab the necessary .dlls

What I want to do is use the Sharepoint mailing system to send an email.

I installed the Nuget Package MicrosoftSharepoint2010 which installed

  • Microsoft.SharePoint
  • Microsoft.SharePoint.Client
  • Microsoft.SharePoint.Client.Runtime
  • Microsoft.SharePoint.Linq
  • Microsoft.SharePoint.Publishing
  • Microsoft.SharePoint.Security
  • Microsoft.SharePoint.Taxanomy
  • Microsoft.SharePoint.Taxanomy.Intl
  • Microsoft.SharePoint.WorkflowActions

I have used this code successfully to read and write to lists..

 Uri uri = new Uri(SharePointConnector.sp_site_address);

 using (ClientContext clientContext = new ClientContext(uri))
  //do stuff

However if I use this code to send an email it tells me I need the assembly for Utilities.EmailProperties

 User sendToUser = clientContext.Web.EnsureUser("robbstark@gmail.com");
 string email = Microsoft.SharePoint.Client.Utilities.Utility.GetCurrentUserEmailAddresses(clientContext).Value;
 Microsoft.SharePoint.Client.Utilities.EmailProperties properties = new Microsoft.SharePoint.Client.Utilities.EmailProperties();
 properties.To = new string[] { sendToUser.Email };
 properties.Subject = "subject";
 properties.Body = "body";

 Microsoft.SharePoint.Client.Utilities.Utility.SendEmail(clientContext, properties);

and If i instead try something like the below I instead get this error

'Could not load file or assembly 'Microsoft.SharePoint.Library, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies.


    using (SPSite oSPSite = new SPSite(SharePointConnector.sp_site_address))  //Site collection URL
        using (SPWeb oSPWeb = oSPSite.OpenWeb("DGPA"))  //Subsite URL
            StringDictionary headers = new StringDictionary();

            headers.Add("from", "me@here.ca");
            headers.Add("to", "me@here.ca");

            headers.Add("subject", "Welcome to the SharePoint");
            headers.Add("fAppendHtmlTag", "True"); //To enable HTML format

            System.Text.StringBuilder strMessage = new System.Text.StringBuilder();
            strMessage.Append("Message from CEO:");

            strMessage.Append("<span style='color:red;'> Make sure you have completed the survey! </span>");
            SPUtility.SendEmail(oSPWeb, headers, strMessage.ToString());

  • sounds like you are using SSOM assemblies in the mix. check this: sharepoint.stackexchange.com/questions/164377/… – Tiago Duarte Sep 12 '17 at 8:17
  • "Utilities.EmailProperties" is part of "Microsoft.SharePoint.Client" assembly which you have added already. The "Could not load file or assembly" error may be because of "Microsoft.SharePoint" dll. If you are using CSOM then there is no need of "Microsoft.SharePoint" dll. so remove it & try. – SP Developer Sep 12 '17 at 11:27
  • The type or namespace name 'EmailProperties' does not exist in the namespace 'Microsoft.SharePoint.Client.Utilities' (are you missing an assembly reference?) – Tim Cadieux Sep 12 '17 at 11:57

You install by using Manage NuGet packages as shown in below image it refer all the client dlls required

enter image description here

you refer the utilities in class file using Microsoft.SharePoint.Client.Utilities;

copy the below code to send emails and test it will send emails. Make sure you give in house(with in domain) email address not out side emails address

    ClientContext ctxSite = new ClientContext("Siteurl");
    string UserID = "user@domain.com";
    string Pwd = "password";

    SecureString _pwd = new SecureString();
    foreach (char c in Pwd.ToCharArray())
     ctxSite.Credentials = new SharePointOnlineCredentials(UserID, _pwd);
    var emailp = new EmailProperties();
    emailp.BCC = new List<string> { "user@domain.com" };
    emailp.To = new List<string> { "user@domain.com" };
    emailp.Body = "<b>Test Email</b>";
    emailp.Subject = "Test subject";
    Utility.SendEmail(ctxSite, emailp);
| improve this answer | |
  • This causes this error - Additional information: Specified argument was out of the range of valid values. Parameter name: SendEmail – Tim Cadieux Sep 12 '17 at 12:38
  • are you trying for which version of SharePoint ? – Suresh Bolineni Sep 13 '17 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.