The default SPUtility
, SendMail
functionality in SharePoint is limited. And you can only send emails to people who are known within the site collection. If you only want to send email to people within site collection, then make sure you use EnsureUser()
to check the availibility in site collection.
Snippet:
private void SendEmail(ClientContext clientContext)
{
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();
}
Refer this good article by Manas Bhardwaj for more.