0

I just figured here out how to open a pre-populated new email message window using c++ on Mac OS X via the "open" command. Unfortunately I couldn't get it to insert both a message body and a subject.

This code should open a new message with a recipient, a subject and a body filled in but it doesn't. Only the recipient and subject are filled in.

mailto:obama@whitehouse.gov?subject=Congrats%20Obama&body=Hello

body is missing

If I remove the subject, it would successfully include the recipient and body such as in this code so the body itself doesn't seem to be incorrectly formatted.

mailto:obama@whitehouse.gov?body=Hello

body successfully filled in Please let me know if you can figure out how to open a "new message" window with both a subject AND a body message.

herteladrian
  • 381
  • 1
  • 6
  • 18

2 Answers2

1

The ampersand (&) is the culprit; everything before it executes in the background and body=... executes separately.

Escape it with a backslash.

Since this is a C++ string, you also need to escape the backslash itself; \\&.

molbdnilo
  • 64,751
  • 3
  • 43
  • 82
  • thank you @molbdnilo for your response but I unfortunately don't understand to escape the body part with a backslash. Can you write out the line for me? This didn't work for me: mailto:obama@whitehouse.gov?subject=Congrats%20Obama\&body=Hello – herteladrian Jun 07 '17 at 14:57
0

This would be the right string to use:

mailto:obama@whitehouse.gov?subject=Congrats%20Obama&body=Hello
Ganesh Sanap
  • 1,386
  • 1
  • 8
  • 18
  • 1
    Please [edit] your answer to explain in more detail how that right string should be used to achieve the goal of the question author. Comparing your answer to the other existing answer, I get the impression that a) it is only parameters b) there is no command c) it does not solve the core of the problem, the use of the unquoted ampersand. I assume that this is an incomplete post, i.e. you are still in the middle of editing. Or any other accident. If you cannot edit this into an answer which is more obviously according to [answer] please delete this. – Yunnosch Feb 21 '23 at 18:42