发送未在Sitecore Web表单中呈现的电子邮件字段对于营销人员

时间:2014-09-02 15:11:51

标签: forms email sitecore sitecore6 web-forms-for-marketers

我的WFFM发送电子邮件保存操作(Sitecore 6.5.0)存在问题。我正在尝试从“发送电子邮件”编辑器的“插入字段”下拉列表中发送包含表单占位符的电子邮件。有时字段会正确呈现,但大多数情况下,电子邮件将包含占位符文本而不是字段的实际值。

例如,这是通过的电子邮件:

First Name: [First Name] 
Last Name: [Last Name] 
Email: [Email Address] 
Company Name: [Company Name] 
Phone Number: [Phone Number] 

我认为它与使用电子邮件模板的富文本编辑器的发送电子邮件编辑器有关,但我尝试调整邮件的HTML无济于事。这就是标记的样子:( <p>标签和标签曾经是内联的,但也不起作用)

<p>First Name:
[<label id="{F49F9E49-626F-44DC-8921-023EE6D7948E}">First Name</label>]
</p>
<p>Last Name:
[<label id="{9CE3D48C-59A0-432F-B6F1-3AFD03687C94}">Last Name</label>]
</p>
<p>Email:
[<label id="{E382A37E-9DF5-4AFE-8780-17169E687805}">Email Address</label>]
</p>
<p>Company Name:
[<label id="{9C08AC2A-4128-47F8-A998-12309B381CCD}">Company Name</label>]
</p>
<p>Phone Number:
[<label id="{4B0C5FAC-A08A-4EF2-AD3E-2B7FDF25AFA7}">Phone Number</label>]
</p>

有谁知道会出现什么问题?

2 个答案:

答案 0 :(得分:3)

之前我遇到过此问题,但使用的是自定义电子邮件操作。我设法通过不使用SendMail类中的弃用方法来修复它,而是使用 Sitecore.Form.Core.Pipelines.ProcessMessage命名空间的ProcessMessageProcessMessageArgs类。

我的用例比你的用例稍微复杂一点,因为我们还附上​​了一个PDF小册子到我们的消息(这就是为什么我们首先使用自定义电子邮件操作),但这里是代码:

public class SendBrochureEmail : SendMail, ISaveAction, ISubmit
{

    public new void Execute(ID formId, AdaptedResultList fields, params object[] data)
    {
        try
        {
            var formData = new NameValueCollection();

            foreach (AdaptedControlResult acr in fields)
            {
                formData[acr.FieldName] = acr.Value;
            }

            var senderName = formData["Your Name"];
            var emailTo = formData["Recipient Email"];
            var recipientName = formData["Recipient Name"];

            var documentTitle = formData["Document Title"];
            if (documentTitle.IsNullOrEmpty())
            {
                documentTitle = String.Format("Documents_{0}", DateTime.Now.ToString("MMddyyyy"));
            }
            Subject = documentTitle;

            if (!String.IsNullOrEmpty(emailTo))
            {
                BaseSession.FromName = senderName;
                BaseSession.CatalogTitle = documentTitle;
                BaseSession.ToName = recipientName;

                var tempUploadPath = Sitecore.Configuration.Settings.GetSetting("TempPdfUploadPath");
                var strPdfFilePath =
                    HttpContext.Current.Server.MapPath(tempUploadPath + Guid.NewGuid().ToString() + ".pdf");

                //initialize object to hold WFFM mail/message arguments
                var msgArgs = new ProcessMessageArgs(formId, fields, MessageType.Email);

                var theDoc = PdfDocumentGenerator.BuildPdfDoc();
                theDoc.Save(strPdfFilePath);
                theDoc.Clear();

                FileInfo fi = null;
                FileStream stream = null;
                if (File.Exists(strPdfFilePath))
                {
                    fi = new FileInfo(strPdfFilePath);
                    stream = fi.OpenRead();
                    //attach the file with the name specified by the user
                    msgArgs.Attachments.Add(new Attachment(stream, documentTitle + ".pdf", "application/pdf"));
                }

                //get the email's "from" address setting
                var fromEmail = String.Empty;
                var fromEmailNode = Sitecore.Configuration.Factory.GetConfigNode(".//sc.variable[@name='fromEmail']");
                if (fromEmailNode != null && fromEmailNode.Attributes != null)
                {
                    fromEmail = fromEmailNode.Attributes["value"].Value;
                }

                //the body of the email, as configured in the "Edit" pane for the Save Action, in Sitecore
                msgArgs.Mail.Append(base.Mail);
                //The from address, with the sender's name (specified by the user) in the meta
                msgArgs.From = senderName + "<" + fromEmail + ">";
                msgArgs.Recipient = recipientName;
                msgArgs.To.Append(emailTo);
                msgArgs.Subject.Append(Subject);
                msgArgs.Host = Sitecore.Configuration.Settings.MailServer;
                msgArgs.Port = Sitecore.Configuration.Settings.MailServerPort;
                msgArgs.IsBodyHtml = true;

                //initialize the message using WFFM's built-in methods
                var msg = new ProcessMessage();
                msg.AddAttachments(msgArgs);
                msg.BuildToFromRecipient(msgArgs);
                //change links to be absolute instead of relative
                msg.ExpandLinks(msgArgs);
                msg.AddHostToItemLink(msgArgs);
                msg.AddHostToMediaItem(msgArgs);
                //replace the field tokens in the email body with the user-specified values
                msg.ExpandTokens(msgArgs);
                msg.SendEmail(msgArgs);

                //no longer need the file or the stream - safe to close stream and delete delete it
                if (fi != null && stream != null)
                {
                    stream.Close();
                    fi.Delete();
                }
            }
            else
            {
                Log.Error("Email To is empty", this);
                throw new Exception("Email To is empty");
            }
        }
        catch (Exception ex)
        {
            Log.Error("Test Failed.", ex, (object) ex);
            throw;
        }
        finally
        {
            BrochureItems.BrochureItemIds = null;
        }
    }

    public void Submit(ID formid, AdaptedResultList fields)
    {
        Execute(formid, fields);
    }

    public void OnLoad(bool isPostback, RenderFormArgs args)
    {
    }

}

WFFM附带的电子邮件操作很可能正在使用已弃用的方法,这可能是您的问题。我没有时间研究它,但您可以反编译DLL并查看他们的电子邮件操作正在做什么。无论如何,上面的代码应该是开箱即用的,除了将字段更新为您正在使用的字段并删除附加PDF的代码,如果您选择没有附件。

祝你好运,编码愉快:)。

答案 1 :(得分:1)

如果您以任何方式更改表单上的字段(captionnametype等),该链接将会更改,您需要重新插入占位符并移动它在您预期的电子邮件中的位置。如果您复制表单也是如此。您必须重新插入电子邮件中的所有字段,否则您将获得上面显示的结果。

重新进行更改将确保收集价值!