简体   繁体   English

通过Sharepoint发送给Outlook的电子邮件中未显示换行符

[英]Linebreaks not displaying in email sent to Outlook via Sharepoint

I'm trying to set up a temporary Sharepoint page that presents a form where users can enter some text and have it emailed off. 我正在尝试建立一个临时的Sharepoint页面,该页面提供一种表单,用户可以在其中输入一些文本并将其通过电子邮件发送出去。 So I have a page containing a form and a submit button that calls some JS to put the entered text into a SOAP request for Sharepoint, which adds it to a list and then sends an email containing that information. 因此,我有一个包含表单和提交按钮的页面,该页面调用一些JS将输入的文本放入对Sharepoint的SOAP请求中,然后将其添加到列表中,然后发送包含该信息的电子邮件。 So far so good, and pretty painless. 到目前为止,一切都很好,而且很轻松。

The issue I'm having is that Outlook ignores any linebreaks that are part of the entered text. 我遇到的问题是Outlook会忽略输入文本中的任何换行符。 They're not being stripped out by anything, since I can use the 'View Source' option and see them normally in Notepad. 它们没有被任何东西剥夺,因为我可以使用“查看源代码”选项并在记事本中正常查看它们。 I figure this is because Outlook's trying to display the message as HTML and doesn't know what to do with them. 我认为这是因为Outlook试图将消息显示为HTML,但不知道该如何处理。 Ordinarily, I'd just throw in some JS that replaces all instances of \\r\\n with <br /> tags, but putting that into the SOAP request just results in anything following the tag being cut off before it gets added to the Sharepoint list. 通常,我会抛出一些JS,用<br />标记替换\\r\\n所有实例,但是将其放入SOAP请求只会导致在标记添加到Sharepoint之前切断标记之后的所有内容名单。

Other things I've tried are 我尝试过的其他事情是

  • Adding a pair of spaces at the start of each new line (no change) 在每个新行的开头添加一对空格(不变)
  • Added a second set of \\r\\n to every linebreak (no change) 向每个换行符添加第二组\\r\\n (不变)
  • Replaced all instances of \\r\\n with %0D%0A (displayed as text) \\r\\n所有实例替换为%0D%0A (显示为文本)
  • Replaced all instances of \\r\\n with \\par (actually used \\\\par , to escape the first backslash). \\r\\n所有实例替换为\\par (实际上使用\\\\par来转义第一个反斜杠)。 (displayed as text) (显示为文本)
  • Appended \\t to all instances of \\r\\n . \\t附加到\\r\\n所有实例。 (no change) (没变)
  • Prepended '.' 前置“。” to all instances of \\r\\n . \\r\\n所有实例。 (periods displayed, but linebreaks did not) (显示了句号,但没有换行)

I'm working with Outlook 2007, Sharepoint 2007, and Internet Explorer 8. 我正在使用Outlook 2007,Sharepoint 2007和Internet Explorer 8。

I've read the questions: 我已经阅读了以下问题:

This is the JS function I'm working with to edit the text, as well as create and POST the SOAP request. 这是我正在使用的JS函数,用于编辑文本以及创建和发布SOAP请求。 It's currently set up to place periods before each linebreak: 目前已设置为在每个换行符之前放置句点:

    function createAndPostSOAP(siteURL, listName)
    {
        var moreText = $("#MoreText")[0].innerText;

        var linebreakCount = moreText.match(/\r\n/g);

        moreText= "  " + moreText;
        for (var count = linebreakCount.length; count >= 0; count--)
        {
            moreText = moreText.replace("\r\n", ".[replace]");
        }

        while(moreText.indexOf("[replace]") != -1)
        {
            moreText = moreText.replace("[replace]", "\r\n");
        }

        var batch = 
            "<Batch OnError='Continue'> \
                    <Method ID='1' Cmd='New'> \
                        <Field Name='Text'>" + $("Text")[0].value + "</Field> \
                        <Field Name='MoreText'>" + moreText + "</Field> \
                    </Method> \
             </Batch>";

         var soapEnv =
                "<?xml version='1.0' encoding='utf-8'?> \
            <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' \
                xmlns:xsd='http://www.w3.org/2001/XMLSchema' \
                xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
               <soap:Body> \
                <UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                  <listName>" + listName + "</listName> \
                  <updates> \
                    " + batch + "</updates> \
                </UpdateListItems> \
              </soap:Body> \
            </soap:Envelope>";

        $.ajax({
        url: siteURL + "/_vti_bin/lists.asmx",
        beforeSend: function(xhr) {
            xhr.setRequestHeader    ("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
        },
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        contentType: "text/xml; charset=utf-8"
        }); 
    window.location='starting_page.htm';
    }

I'm mostly attacking this from the Javascript end, because I know that better than Sharepoint, but is there a way in Sharepoint 2007 to have a script change the linebreaks into <br /> once the data is already added to the column? 我主要是从Javascript端开始进行攻击,因为我知道它比Sharepoint更好,但是一旦将数据添加到列中,Sharepoint 2007中是否有办法让脚本将换行符更改为<br /> Or is there an angle I missed in the Javascript? 还是我在Java语言中错过了一个角度?

You need to encode all your HTML tags in the code. 您需要在代码中对所有HTML标记进行编码。 Meaning for 的意义

&amp; → & (ampersand)
&lt; → < (less-than sign)
&gt; → > (greater-than sign)
&quot; → " (quotation mark)
&apos; → ' (apostrophe)


Try the below code: 试试下面的代码:

String Input = "adding this text <br/> this in next line <>";
String Output = Server.HtmlEncode(Input);
//

If required 如果需要的话

Output = Output.Replace("\r\n", "<br />");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM