2014-09-02 66 views
2

我遇到了WFFM发送电子邮件消息保存操作(Sitecore 6.5.0)的问题。我正尝试发送一封电子邮件,其中包含“发送电子邮件”编辑器中“插入字段”下拉列表中的表单占位符。有时这些字段将正确呈现,但大多数情况下,电子邮件将包含占位符文本,而不是字段的实际值。发送电子邮件字段不在Sitecore Web表单中呈现给营销人员

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

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> 

有谁知道什么可以去错了吗?

回答

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

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

重新插入更改将确保收集价值!

相关问题