This article informs you as to how to send a notification e-mail related to a BizForm from the code.
The SendNotificationEmail method in the BizForm object needs to be called from the Form object, which is filled with all required data, otherwise the macros in the e-mail won’t be resolved and notifications won’t send at all.
The following code example shows you, how to send a notification e-mail from the default Contact Us On-line Form in the sample Corporate Site:
string bizFormName = "ContactUs"; // choose a Form
BizFormInfo bizFormInfo = BizFormInfoProvider.GetBizFormInfo(bizFormName, CMSContext.CurrentSiteID);
DataClassInfo dataClassInfo = DataClassInfoProvider.GetDataClass(bizFormInfo.FormClassID);
if (dataClassInfo != null)
{
var connection = ConnectionHelper.GetConnection();
var whereCondition = String.Format("ContactUsID = '{0}'", 1); // choose a row
var dataSet = connection.ExecuteQuery(dataClassInfo.ClassName + ".selectall", null, whereCondition);
if (!DataHelper.DataSourceIsEmpty(dataSet) && dataSet.Tables[0].Rows.Count == 1)
{
DataRow dataRow = dataSet.Tables[0].Rows[0];
BizForm bizForm = new BizForm();
BizFormItem bizFormItem = new BizFormItem(dataRow, dataClassInfo.ClassName);
if ((bizFormItem != null) && (bizFormInfo != null))
{
BasicForm basicForm = new BasicForm(bizFormItem);
basicForm.SiteName = CMSContext.CurrentSiteName;
basicForm.EditedObject = bizFormItem;
basicForm.FormInformation = CMS.FormEngine.FormHelper.GetFormInfo("BizForm.ContactUs", true); // set required FormInfo
bizForm.BasicForm = basicForm;
bizForm.SendNotificationEmail(bizFormInfo.FormSendFromEmail, bizFormInfo.FormSendToEmail, bizFormItem, bizFormInfo);
}
}
}
-jh-
See also:
Applies to:
Kentico CMS 6.x
Created on
5/31/2012 6:45:05 AM in
Forms (BizForms)