public bool SendEmail(string To, string cc, string subject, string msg)
{
bool status = true;
string sendTo = To;
string CCTo = cc;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSpSite = new SPSite(SPContext.Current.Web.Url))
{
oSpSite.AllowUnsafeUpdates = true;
using (SPWeb oSPWeb = oSpSite.OpenWeb())
{
oSPWeb.AllowUnsafeUpdates = true;
if (SPUtility.IsEmailServerSet(oSPWeb))
{
StringDictionary headers = new StringDictionary();
headers.Add("to", sendTo);
headers.Add("cc", CCTo);
headers.Add("subject", subject);
headers.Add("fAppendHtmlTag", "True");
System.Text.StringBuilder strMessage = new System.Text.StringBuilder();
strMessage.Append(msg);
status = SPUtility.SendEmail(oSPWeb, headers, strMessage.ToString());
}
oSPWeb.AllowUnsafeUpdates = false;
}
oSpSite.AllowUnsafeUpdates = false;
}
});
return status;
}
catch (Exception ex)
{
this.Print("SendBulkEmail", ex.Message);
return false;
}
}
No comments:
Post a Comment