我正在尝试通过我的 MVC Web 应用程序上的 api 提交一个新的表单项(从表单的代码选项卡中获取代码),但电子邮件通知不起作用。除了电子邮件警报之外,它确实创建了一条新记录。我检查了电子邮件队列,但没有表单项的记录。我正确配置了 smtp 服务器设置。我也检查了事件日志,但没有看到任何错误。我是否遗漏了什么或此功能仅在门户引擎上?
问问题
164 次
1 回答
0
显然,如果我们通过代码手动提交表单而不使用默认的 mvc 表单小部件,它不会自动触发通知。我们还需要通过代码发送通知。表格数据文档
// Gets the form object representing the 'ContactUs' form on the current site
BizFormInfo formObject = BizFormInfoProvider.GetBizFormInfo("ContactUs", SiteContext.CurrentSiteID);
if (formObject != null)
{
// Gets the class name of the 'ContactUs' form
DataClassInfo formClass = DataClassInfoProvider.GetDataClassInfo(formObject.FormClassID);
string formClassName = formClass.ClassName;
// Creates a new data record for the form
BizFormItem newFormItem = BizFormItem.New(formClassName);
// Sets the values for the form's fields (UserMessage in this case)
newFormItem.SetValue("UserMessage", "This is a message submitted through the API.");
// Saves the new form record into the database
// Set values for all 'Required' fields in the form before calling the Insert method, otherwise an exception will occur
newFormItem.Insert();
// Obtains a factory object used to create a form notification sender service for the given form
IBizFormMailSenderFactory senderFactory = Service.Resolve<IBizFormMailSenderFactory>();
// Creates an instance of the form notification sender for the inserted form item
IBizFormMailSender sender = senderFactory.GetFormMailSender(formObject, newFormItem);
// Sends a notification email to users (as specified on the form's 'Email notification' tab)
sender.SendNotificationEmail();
// Sends a confirmation email to the submitter (based on the form's autoresponder settings)
sender.SendConfirmationEmail();
}
于 2019-05-13T18:18:54.960 回答