Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Is this function working in V6.0 bizForm.SendNotificationEmail() View modes: 
User avatar
Member
Member
knottano-gmail - 5/3/2012 1:06:56 AM
   
Is this function working in V6.0 bizForm.SendNotificationEmail()
I am trying this code many times. But no email is sent.


string bizFormName = "ContactUs";

BizFormInfo bizFormInfo = BizFormInfoProvider.GetBizFormInfo(bizFormName, CMSContext.CurrentSiteID);

DataClassInfo dataClassInfo = DataClassInfoProvider.GetDataClass(bizFormInfo.FormClassID);

if (dataClassInfo != null)
{
var connection = ConnectionHelper.GetConnection();
var whereCondition = String.Format("ItemID = '{0}'", 1);

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)
{
bizForm.SendNotificationEmail(bizFormInfo.FormSendFromEmail, bizFormInfo.FormSendToEmail, bizFormItem, bizFormInfo);
bizForm.SendConfirmationEmail(bizFormInfo.FormSendFromEmail, bizFormInfo.FormSendToEmail, bizFormItem, bizFormInfo);
}
else
{
Response.write("data is null");
}
}
}


Please help,
thank you

User avatar
Kentico Support
Kentico Support
kentico_janh - 5/3/2012 2:16:45 AM
   
RE:Is this function working in V6.0 bizForm.SendNotificationEmail()
Hello,

Have you tried to debug your code to find out, where it ends? Please make sure, that the bizFormItem is not null, so the SendNotificationEmail method runs.

Best regards,
Jan Hermann

User avatar
Member
Member
knottano-gmail - 5/3/2012 2:25:54 AM
   
RE:Is this function working in V6.0 bizForm.SendNotificationEmail()
Hi Jan,

It's not null for sure.

I can print out the value of bizFormItem which is all correct.


User avatar
Kentico Support
Kentico Support
kentico_janh - 5/3/2012 9:13:14 AM
   
RE:Is this function working in V6.0 bizForm.SendNotificationEmail()
Hello,

The problem is, that after the SendNotificationEmail method is called it checks if its parameters are not null (which are filled properly in your code) but it also checks, if the BasicForm property of that BizForm is not null (and it is in your case), so you need to define this BasicForm before you call that method:

BasicForm basicForm = new BasicForm(formData);
basicForm.FormInformation = ...;
basicForm.SiteName = ...;
basicForm.EditedObject = formItem;
bizform.BasicForm = basicForm;


Or you can just create and fill your email manually and send it by using our API and CMS.EmailEngine.EmailSender class.

Best regards,
Jan Hermann

User avatar
Member
Member
knottano-gmail - 5/3/2012 6:32:35 PM
   
RE:Is this function working in V6.0 bizForm.SendNotificationEmail()
string bizFormName = "ContactUs";

BizFormInfo bizFormInfo = BizFormInfoProvider.GetBizFormInfo(bizFormName, CMSContext.CurrentSiteID);

DataClassInfo dataClassInfo = DataClassInfoProvider.GetDataClass(bizFormInfo.FormClassID);

if (dataClassInfo != null)
{
var connection = ConnectionHelper.GetConnection();
var whereCondition = String.Format("ItemID = '{0}'", 1);

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)
{

BasicForm basicForm = new BasicForm(bizFormItem);
basicForm.SiteName = CMSContext.CurrentSiteName;
basicForm.EditedObject = bizFormItem;
basicForm.FormInformation = new FormInfo("");
bizForm.BasicForm = basicForm;

bizForm.SendNotificationEmail(bizFormInfo.FormSendFromEmail, bizFormInfo.FormSendToEmail, bizFormItem, bizFormInfo);
bizForm.SendConfirmationEmail(bizFormInfo.FormSendFromEmail, bizFormInfo.FormSendToEmail, bizFormItem, bizFormInfo);
}
else
{
Response.write("data is null");
}
}
}


Now the email is sent with the correct template in "Notification e-mail" and also "Autoresponder". But the value of the form does not replace the variable in the template.

I am expect the the email to send out the same way when I submit the form with all the $$value:Fname$$ and $$value:Lname$$ etc ... to be replaced with the data in bizFormItem.

Could you give me more information how to do this please?

Thank you

User avatar
Kentico Support
Kentico Support
kentico_janh - 5/4/2012 3:41:11 AM
   
RE:Is this function working in V6.0 bizForm.SendNotificationEmail()
Hello,

That is bacause you have filled basicForm.FormInformation with an empty FormInfo and the macro resolution is based on this FormInfo, so please replace it with a right class name:

basicForm.FormInformation = CMS.FormEngine.FormHelper.GetFormInfo("BizForm.ContactUs", true);


Best regards,
Jan Hermann