Monday, January 23, 2012

Send an email from Sharepoint using SPUtility class


Send an email from Sharepoint using SPUtility class

public static void SendMail(SPWeb pCurrentWeb, string pSubject, string pBody, string pTo, string pFrom)
        {
            StringDictionary emailDict = new StringDictionary();
            try
            {
                if (!string.IsNullOrEmpty(pFrom) && !string.IsNullOrEmpty(pTo))
                {
                    emailDict.Add("to", pTo);
                    emailDict.Add("from", pFrom);
                    emailDict.Add("subject", pSubject);
                    emailDict.Add("content-type", "text/html");
                    SPUtility.SendEmail(pCurrentWeb, emailDict, pBody);
                }
            }
            catch (Exception ex)
            {
                //Log error here
            }
        }

No comments:

Post a Comment