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..
Business.Utility.loadConfigurations();
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("[email protected]");
clientContext.Load(sendToUser);
clientContext.ExecuteQuery();
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);
clientContext.ExecuteQuery();
and If i instead try something like the below I instead get this error
'Could not load file or assembly 'Microsoft.SharePoint.Library, Version=14.0.0.0, 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", "[email protected]");
headers.Add("to", "[email protected]");
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());
}
}