Wednesday, December 30, 2015

SharePoint Emails

Send email per https://www.collaboris.com/blogs/collaboris-blog/mark-jones/2012/11/06/code-sample-how-to-programmatically-send-an-email-in-sharepoint#.VoH5A_krLak or using straight smtpclient per http://sharepoint.stackexchange.com/questions/98192/issue-when-setting-from-in-the-sputility-sendemail. In the end used this: http://www.sharepointbriefing.com/spcode/article.php/3840566/How-To-Send-Email-with-SPUtility.htm slightly modified:

        private static Boolean SendEmail(SPWeb web, string email, string subject, string body)
        {
            try
            {
                bool flag = false;
                SPSecurity.RunWithElevatedPrivileges(
                  delegate ()
                  {
                              flag = SPUtility.SendEmail(web, true, true,
                                             email,
                                             subject,
                                             body);
                  });
                return flag;
            }
            catch (System.Exception exp)
            {
                // Do some error logging
                return false;
            }
        }


No comments:

Post a Comment