Some time ago we faced with the following problem: when send email via CSOM using Utility.SendEmail method we got the following error:
The e-mail message cannot be sent. Make sure the e-mail has a valid recipient.
When Sharepoint processes request from Utility.SendEmail method on server side it uses SPUtility.SendEmail_Client internal method:
As you can see it throws GetInvalidRecipientsException in 2 cases:
- when To recipients are not specified (line 11)
- when another internal method SPUtility.ResolveAddressesForEmail method doesn’t calls provided delegates for To, Cc and Bcc recipients and as result appropriate recipients lists are empty (line 46)
In our case To recipient was specified for sure, so the only reason was problems in SPUtility.ResolveAddressesForEmail method: because of some reason it didn’t resolve specified recipient. Let’s see the code of this method:
As you can see it internally uses SPUtility.ResolvePrincipal method which resolve principals based on provided parameters. I tried to call this method for recipient which we specified for Utility.SendEmail and it returned not-null principal:
But PrincipalId property of returned object was negative (-1). As result SPUtility.ResolveAddressesForEmail method didn’t use this principal and added the following line to the log (lines 25-35):
ResolveAddressesForEmail : Resolved input 'domain\user' is not registered as the site collection user, ignored.
The problem was in the format which we used for specifying email recipient: we used “domain\user” format, while the correct way is to use claims format “i:0#.w|domain\user”. After changing the code emails start working.