Last active
April 12, 2017 10:55
-
-
Save zplume/dc897e57488bb3a4c553345f978724a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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