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:person@place.com?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:person@place.com?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:person@place.com?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.