简体   繁体   中英

HTML mailto link with body text; outlook adding unwanted line break

When generating an email draft with body text from an HTML mailto link, Outlook's default formatting settings automatically add a line break after lines exceeding 120 characters that end with a line break (%0D%0A). Anyone know how I might prevent this from happening? My assumption is that this is how Outlook will behave and I won't be able to change that, at least not from the mailto link.

Let me know if you need any additional information or if I am being unclear. Thank you for your time.

EDIT: example jsfiddle : https://jsfiddle.net/q7rc1y65/2/

The only valid way to generate line breaks with the mailto: command is to use %0D%0A . Unfortunately Outlook automatically formats messages and treats text longer than 120 characters with a line break as a paragraph. You can see this by pressing ctrl+shift+8.

You can change how this behaves on your own install of outlook See Here , but you cannot use the mailto: command to control this behavior. An alternative solution would be to use an email form instead of the mailto link, then send the email server side. Here you have much greater control over the look and structure of the body and would have the ability to create html emails as well.

Here is the updated fiddle demonstrating your issue: JSFIDDLE .

<a href="">MAIL!</a> 
<br /><br />
MAILTO HREF:
<div id='linkText'></div>

$().ready(function () {
    var returnChar = encodeURIComponent('%0D%0A');    
    var subject = encodeURIComponent('this is the subject');    
    var body = encodeURIComponent('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nos ');
    var bodySub120 = encodeURIComponent('Lorem ipsum dolor sit amet, consectetur adipiscing elit ');

    var href = 'mailto:someone@somewhere.com?subject=' + subject + '&body=';
    var href= href + bodySub120 + returnChar + bodySub120 + returnChar + body + returnChar + body + returnChar;
    $('a').attr("href", href);
    $('div#linkText').text(href);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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