0

Can I trigger my Mac to open the default mail client "new message" window from my C++ program. It should work just like a mailto link does. When the program runs it should open a "new message" window with a message body, a subject line, and a recipient already filled in. I DON'T need to include an attachment. I know there are some answers already on Stack Overflow addressing that question. A mailto link with the functionality I need looks something like this:

    "mailto:bob@domain.com?subject=look at this website&body=Hi,I found this website."

If it is not possible to use mailto directly in C++, is there some other way of doing what I am looking for?

Thank you for your help!

herteladrian
  • 381
  • 1
  • 6
  • 18
  • after googling around for a few minutes, it looks like this is likely what you want: https://developer.apple.com/documentation/coreservices/1442850-lsopencfurlref header file: https://github.com/phracker/MacOSX-SDKs/blob/master/MacOSX10.3.9.sdk/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Headers/LSOpen.h#L166 It's likely a PITA to call from C/C++, but it is do-able. "launch services" seems to be the concept you are looking for to learn more. I've never done any of the above. – xaxxon Jun 07 '17 at 07:19
  • thank you for your help and efforts! @xaxxon. I just posted my own answer. turned out to be PITA-free! – herteladrian Jun 07 '17 at 08:06

1 Answers1

0

This simple code does what I need! It launches the default mail client window with a given recipient address, subject, and message body. "email", "subject", and "bodyMessage" are all string variables declared in my complete program code. This snippet doesn't include their declarations.

       string mailTo = "mailto:" + email + "?subject=" + subject + "\\&body=" + bodyMessage;
       string command = "open " + mailTo;
       system(command.c_str());

This post on using the "open" command helped.

herteladrian
  • 381
  • 1
  • 6
  • 18
  • 1
    I edited your answer to remove the follow-up question. If you have follow-up questions, please [ask a new question](https://stackoverflow.com/questions/ask) instead of posting a comment or answser. – You Jun 07 '17 at 08:17