How to Send email to External users in SharePoint online using CSOM?

Hello SharePointers,

Below is the CSOM code to send email to External users in SharePoint online using CSOM

string Url = “https://tenant.sharepoint.com/sites/comms/”;
var cc = new ClientContext(Url);
string passwordPlainText = “userpassword”;
string currentUserLoginName = “user@tenant.onmicrosoft.com”;
var passWord = new SecureString();
foreach (char c in passwordPlainText.ToCharArray()) passWord.AppendChar(c);
cc.Credentials = new SharePointOnlineCredentials(currentUserLoginName, passWord);

web.EnsureUser(“i:0#.f|membership|paige.turner_contoso.com#ext#@tenant.onmicrosoft.com”);
clientContext.ExecuteQuery();

var emailProperties = new EmailProperties();
//Email of authenticated external user
emailProperties.To = new string[] { “Laks.Sethu@contoso.com” };

emailProperties.Body = “This is the email body”;
emailProperties.Subject = “This is the email subject”;
Utility.SendEmail(clientContext, emailProperties);

cc.ExecuteQuery();

Happy SharePointing 🙂

Leave a Reply

Your email address will not be published.