Tuesday, August 13, 2019

How to Send email via SharePoint Client Context - SendMailViaCtx

How to Send email via SharePoint Context,


Get User Name, Password, Hub Manager email, User email, From an email  from Config as per your requirements.



 try
                            {
                                SecureString secPwd = new SecureString();
                                foreach (var p in password)
                                {
                                    secPwd.AppendChar(p);
                                }
                                secPwd.MakeReadOnly();
                                using (var clientContext = new ClientContext("https://{Tenant}.sharepoint.com"))
                                {
                                    clientContext.Credentials = new SharePointOnlineCredentials(userName, secPwd);
                                    var emailp = new EmailProperties();
                                    emailp.BCC = new List<string> { user.Email };
                                    emailp.To = new List<string> { hubManagersEmail };
                                    emailp.From = userName;
                                    emailp.Body = "<b>Hi Moderators, <p>Please review the the Page data as tool found blocked words in page</p><p>Regards,</p><p>Admin Team</p></b>";
                                    emailp.Subject = "Profanity Alert! ! Found blocked words in page";
                                    Utility.SendEmail(clientContext, emailp);
                                    clientContext.ExecuteQuery();
                                    log.Info("Sent Email on Blocked words");
                                }

                            }
                            catch (Exception)
                            {
                                log.Info("Error while Sending email");
                            }


OUTPUT EMAIL LOOKS AS BELOW:



No comments:

Post a Comment

Building Secure Azure AI Foundry Agents with Managed Identity

  The credential problem nobody wants to own Every team that connects an Azure AI Foundry agent to Microsoft Graph, SharePoint, Outlook, or...