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:

Update or edit status filed in JIRA issue

the status field is a special case and can't be updated directly, which is the second problem here. Changing a status in Jira is called ...