Good Evening,

I'm working on a program that will allow user input and will take that input, insert it into blank spots into an email template, and then prepopulate the email template in Outlook so all an analyst would need to do is click a the send button - basically a dummy proof program to send emails to customers.

Creating the interface and reading the information entered isn't an issue; however, I just figured out how to get an email to open but have no idea how to format the body. The below code I just happened upon at https://stackoverflow.com/questions/25189365/shellexecute-for-mailto-doesnt-work-with-google-chrome which managed to get the email to open as long as Outlook is already open. The problem is, I have no idea what the shellExecute line is or how to manipulate it to add user provided information into an outlook email template file. Does anyone know of any resources that are available that would provide information on chopping up an outlook template file and injecting data into the template?

Here's the code I have that opens a blank email:

#include "stdafx.h"
#include <iostream>
#include <shlobj.h>
#include <shlwapi.h>
#include <objbase.h>

int main()
{
    LPCTSTR addr = L"mailto:myaddress@gmail.com";
    ShellExecute(0, _T("open"), addr, NULL, NULL, SW_SHOWNORMAL);
    return 0;
}

I got this to add a subject and some stuff in the body, I just need to figure out how to make it html and include jpg's and formated tables.

    LPCWSTR addr = L"mailto:john@mycompany.com?CC= boss@mycompany.com&Subject= Meet for lunch&Body= Please join me for a sandwich at noon.";
    ShellExecute(0, _T("open"), addr, NULL, NULL, SW_SHOWNORMAL);

So after alot of playing around, I came up with this (which isn't exactly what I need)

#include "stdafx.h"
#include <string>
#include <iostream>
#include <shlobj.h>
#include <shlwapi.h>
#include <objbase.h>

using namespace std;

int main()
{
    LPCWSTR addr = L"mailto:john@mycompany.com?CC= boss@mycompany.com&Subject= ";
    //Meet for lunch&Body = ";
    //convert addr to wstring
    wstring myaddr(addr);
    wstring incident, second;
    wstring message;

    cout << "Enter the incident number: ";
    getline(wcin, incident);
    if (!wcin.good()) return 0;

    cout << "Enter a message below" << endl << endl;
    wcin >> message;

    //add incident to the subject line and add a blank body tag
    wstring concat = addr + incident + L"&Body= " + message;
    wcout << concat;
    system("pause");
    LPCWSTR finished = concat.c_str();
    ShellExecute(0, _T("open"), finished, NULL, NULL, SW_SHOWNORMAL);
    return 0;
}

The actual email template includes a table with several .jpg pictures. I found a library called magick++ but I don't see how I can use this to add a table and pictures into an html enabled email.

I'll back burner this project until I understand better how I can interface with Outlook. For now, the best I got is a MadLibs email.

My first question is, how does this improve over the mail merge functionality that nearly every SMTP mail reader has had since the 1980s? Outlook has been able to do this out of the box since it came out - heck, Outlook Express could do it, for that matter, back when that was a thing.

Now, it is possible you do have a better mousetrap in mind, but if so, you have not explained how it is better. Conversely, if you are climbing this mountain because it is there, that is fine too, but the way you are speaking of it gives the impression that this is part of a larger project.

Having said that, allow me to address the question itself. I recommend forgetting about using ShellExecute(), and looking into the Office API to work with Outlook directly. You will probably want the Add-Ins API rather than the web-focused Graph REST API, though you will need to look over both to be certain.

Keep in mind that the current Office 365 version is a Software-as-a-Service package; the Office application executable is just a launcher for the cloud application, comparable to an Electron wrapper on a webapp, meaning that Outlook (and Word, Excel, and the rest) is no longer a stand-alone program at all. Older versions of Outlook worked rather differently, though the ordinary user wouldn't be able to tell the difference.

Schol-R-Lea,

Thanks for the reply. I'll look into what you suggested. You are correct, it's part of a bigger project and it's also a little bit of "because it's there and I want to see if it's possible". I work with a local desk in the US and a desk in Barcelona so I'm trying to create something that forces everyone to use the exact same email template. I can't think of a better way than creating a Windows GUI with input boxes asking for input, having the agent click a button, and then having the program open an email using the default email program (which is Outlook 2016 in this case) with the template already filled in.