In the client object model for SharePoint Online we have the Utility class. This class provides a function SendEmail() that (oh wonder) helps us to send emails. In my tests, I found that the recipient must be a member of the hidden “All People” group in the SharePoint site, from where we take the client context. So, to successfully send an email with this function, the code should look like this:


string userMail = "alexw@anytenant.onmicrosoft.com";

Web web = ctx.Web;
web.EnsureUser(userMail);
ctx.ExecuteQueryRetry();

EmailProperties mailProps = new EmailProperties();
mailProps.From = "noreply@anytenant.onmicrosoft.com";
mailProps.To = new string[] { userMail };
mailProps.Subject = "Email Tester";
mailProps.Body = @"<html><body><h1 style='color: red;'>Header</h1><br/><div>Hello world.</div></body></html>";

Utility.SendEmail(ctx, mailProps);
ctx.ExecuteQueryRetry();

Very important for the recipients: they must be a user in the current tenant. In my tests, it was not possible to send emails to external users, even when they have permissions in the SharePoint site of the client context.

Advertisements