Govind
Govind

Reputation: 449

Getting error in large body content in mailto

I am working on the following script for mailing the data dynamically entered by the user .This works fine for the content with lesser data and Outlook window is opening properly with the data.But when I use this same logic for the larger data . I am getting error while opening the Outlook window stating "The command line argument is not valid. Verify the switch you are using".Refer this link for the error (http://support.citrix.com/article/CTX123773) occurred What could be the reason for this .Kindly help with this issue.

Thanks in advance .

<html>
<head>
  <script>
    var bodyScript = " ";
    var json = " ";

    function ajaxCall() {
      ajax {
        url: function: loadDetails,
        error: ,
      }
    }

    function loadDetails() {
      bodyScript += "Hi" + json.Name;
      .....
      bodyScript += "%0D%0Awelcome to our Camp .Your ID is " + json.ID;
      .....
    }

    function sendEmail() {
      var link = "mailto:" +
        +"?cc=Sam&subject=test&body=" + bodyString;
      alert('bodyString before mailing ' + bodyString);
      window.location.href = link;
    }
  </script>

  <body>
    <div id=”btnSubmit” onclick=sendEmail()”>click me</div>
  </body>
</html>

Upvotes: 0

Views: 1382

Answers (1)

Sev
Sev

Reputation: 1992

Try encodeURIComponent(bodyString), there seems to be some characters (possible quotes) that mess with the command-line options:

var link = "mailto:"+
+"?cc=Sam&subject=test&body="+encodeURIComponent(bodyString);

I see that on the example you already urlencode somehow the line breaks. So instead of just using encodeURIComponent(bodyString) you maybe will have to turn it into encodeURIComponent(decodeURIComponent(bodyString))

Demo: http://jsfiddle.net/H9ERc/

Upvotes: 1

Related Questions