This morning, I decided to just create a form submission handler to do the job. This might be the better approach in any case, so that you don't have to create too many checkboxes for all the various ways people might like to tweak the default behavior of FWP.
Here's the code (to try and use the question alias text in the generated e-mail) in case it saves anyone a few minutes:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using log4net;
using sts.Business;
using mojoPortal.Business;
using sts.FormWizard.Web.UI;
using mojoPortal.Net;
using mojoPortal.Web;
using System.Configuration;
namespace MojoMailerByQuestionAlias
{
public class MojoFWPMailer : FormSubmissionHandlerProvider
{
private string _FromEmailAddress = ConfigurationManager.AppSettings["MojoMailerFromAddress"];
private List<string> _ToEmailAddresses;
private static readonly ILog log = LogManager.GetLogger(typeof(MojoFWPMailer));
public MojoFWPMailer()
{ }
public override void FormSubmittedEventHandler(object sender, FormSubmissionEventArgs e)
{
if (e == null) return;
if (e.ResponseSet == null) return;
log.Info("MojoFWPMailerFormSubmissionHandlerProvider called");
StringBuilder results = new StringBuilder();
// grab to e-mail addresses
// I'm grabbing the "to" e-mails from the "Display Aliases for Email Addresses" box, bc I'm not using this field, and it allows content admins to specify the addresses themselves
// If addresses are stored in the usual place, "Email Address(es) to Receive Form Submissions", mojo will send out its own e-mail in addition to this one
_ToEmailAddresses = e.Config.EmailAliases;
// notify admins to whom the email is sent
results.Append(string.Format("This message has been sent to {0}", string.Join(",", _ToEmailAddresses.ToArray())));
// assemble questions and answers
List<WebFormQuestion> questionList = WebFormQuestion.GetByForm(e.ResponseSet.FormGuid);
List<WebFormResponse> responses = WebFormResponse.GetByResponseSet(e.ResponseSet.Guid);
results.Append("<p>");
foreach (WebFormQuestion question in questionList)
{
if (question.QuestionTypeId == 8) { continue; } //skip instruction block
//// this is an e-mail question type
//if (question.QuestionTypeId == 10) {
// _FromEmailAddress = GetResponse(e.ResponseSet.Guid, question.Guid, responses);
//}
string response = GetResponse(e.ResponseSet.Guid, question.Guid, responses);
if (!string.IsNullOrEmpty(question.QuestionAlias))
results.Append(string.Format("<strong>{0}: </strong>{1}<br />", question.QuestionAlias, response)); // first try question alias
else
results.Append(string.Format("<strong>{0}: </strong>{1}<br />", question.QuestionText, response)); // if it's blank, then just use the question text
}
results.Append("</p><hr>");
// how to get the site user if the user was authenticated
if (e.User != null)
{
results.Append(string.Format("<p>submitted by user {0}</p>", e.User.Name));
}
// add detail link
results.Append(string.Format("<p>{0}</p>", e.DetailUrl));
//how to send an email with the results and file attachments
//you could get settings from config settings if you don't want to hard code it
//you would need references to mojoPortal.Web.dll, mojoPortal.Business.dll, and mojoPortal.Net.dll
//to use this commented code
string subject = e.Config.PickListLabel; //can't see how to get subject off-hand, so am using a different field that I wouldn't otherwise use
foreach (string email in _ToEmailAddresses)
{
Email.SendEmail(
SiteUtils.GetSmtpSettings(), // smtp settings
_FromEmailAddress, // from
email, // to
string.Empty, // cc
string.Empty, // bc
subject, // subject
results.ToString(), // body
true, // is html email?
Email.PriorityNormal); // priority
log.Info(results.ToString());
}
}
private string GetResponse(Guid responseSetGuid, Guid questionGuid, List<WebFormResponse> responses)
{
foreach (WebFormResponse response in responses)
{
if (
(response.ResponseSetGuid == responseSetGuid)
&& (response.QuestionGuid == questionGuid)
)
{
return response.Response;
}
}
return string.Empty;
}
}
}