Skip to content

Instantly share code, notes, and snippets.

@zplume
Last active April 12, 2017 10:55
Show Gist options
  • Save zplume/dc897e57488bb3a4c553345f978724a3 to your computer and use it in GitHub Desktop.
Save zplume/dc897e57488bb3a4c553345f978724a3 to your computer and use it in GitHub Desktop.
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Utilities;
using System.Collections.Generic;
public static class Email
{
public static void Send(ClientContext ctx, string[] to, string subject, string body, bool html = false)
{
var properties = new EmailProperties();
properties.To = to;
properties.Subject = subject;
properties.Body = body;
if (html)
{
properties.Body = $@"
<html><head><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8\"">
<title>{properties.Subject}</title></head>
<body>
{properties.Body}
</body>
</html>";
properties.AdditionalHeaders = new Dictionary<string, string>();
properties.AdditionalHeaders.Add("Content-Type", "text/html; charset=\"UTF-8\"");
}
foreach (var e in to)
ctx.Web.EnsureUser(e);
Utility.SendEmail(ctx, properties);
ctx.ExecuteQueryRetry();
}
public static void Send(ClientContext ctx, string to, string subject, string body, bool html = false)
{
Send(ctx, new string[] { to }, subject, body, html);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment