The command line argument is not valid verify the switch you are using

7.5k views Asked by At

I am trying to open a Outlook when user clicks on submit button of form by using javascript mailto:

When I submit the form from chrome or firefox then it is able to open but in IE I am getting the following error:

The command line argument is not valid verify the switch you are using

2

There are 2 answers

1
Keews On

I'm not really sure you did research much, but the first result in google when you look up for the error leads to a Microsoft board where it seems to be solved:

https://support.microsoft.com/en-us/kb/312346

As far as I've seen, your problem is related with a file association to the URI Schema "mailto". I'd recommend following the steps you can find in the link and searching exhaustively next time.

0
Nate Anderson On

The Microsoft Knowledge Base article was helpful, but it was only a workaround:

  • i.e. if I change my default program to "Mail Express" (Windows 10), clicking mailto in IE does not cause issue; the email opens in "Mail Express" and can be sent immediately
  • However, if I change default program back to "Outlook 2016" (Windows 10), clicking mailto in IE does cause the issue: "The command line argument is not valid verify the switch you are using"

Problem:

My mailto value comes from Angular, and my mailto has special characters. I can only recreate this issue using Angular's ng-href (JSFiddle) I cannot recreate the issue with plain HTML (JSFiddle)).

Solution:

Solution JSFiddle here; again my problem is specific to Angular/ng-href, so my solution uses Angular/ng-href.

In my case my mailto href attribute value included double-quotes (i.e. '"'). The double quotes were escaped (with a backslash), but they weren't encoded I needed to URLEncode my mailto value. This is intuitive because href attribute usually points at a URL, and URLs require percent-encoding.

<a href="mailto:[email protected]?subject=Subject includes \"double-quotes\"">Mail link</a>

When I encodeURIComponent only the subject value: encodeURIComponent("Subject includes \"double-quotes\"") and update that part. The result is here; notice %20 and %22 in the new subject:

<a href="mailto:[email protected]?subject=Subject%20includes%20%22double-quotes%22">Mail link</a>

Note:

I had double-quotes (i.e. '"', or %22), but a different character may cause the issue: I suspect other URL-unsafe characters may cause this issue.

Looks like the space (i.e. ' ' , or %20), was not causing a problem, even before encoding. After I started using encodeURIComponent, I probably fixed any/all other fancy characters that may have caused the issue, i.e. '&' or others...)

I'm not sure if the parameters have different requirements; i.e. is subject parameter treated differently than the body parameter, or the implied to parameter. So I used encodeURIComponent for both subject and body.

Be careful not to over-encode. Only encode the separate subject and body parameters:

  • Do not encode the colon (i.e. : which follows mailto); browsers may fail to recognize this is a mailto link (see solution)
  • Do not encode the question marks (i.e. ?) or the equals signs (i.e. =); browsers/Outlook may fail to parse the parameters (see solution)

So when I encode:

encodeURIComponent("mailto:[email protected]?subject=Subject includes \"double-quotes\"")

Notice the results; wrongly encoded the colon (i.e. %3A) and the equals sign (%3D)

 "mailto%3Aperson%40place.com%3Fsubject%3DSubject%20includes%20%22double-quotes%22"

Be careful not to double-encode, i.e. encode a string which is already encoded!

I will remove the Java tag from the question; I agree with comments I don't think Java is relevant.