在c ++中发送outlook电子邮件

时间:2014-11-13 18:16:16

标签: c++ outlook email-integration

我正在使用c ++程序,需要在c ++程序中生成一封电子邮件,然后发送给outlook。 我到目前为止尝试使用的代码是这样的

system("cmd /c OUTLOOK.EXE /c ipm.note /m \"firstmail@mail.com&cc=ccmail@mail.com&subject=\"TestEmail\"&body=Hello%20World\"");

当我运行它时,它将生成电子邮件并填写TO字段,但不填写CC,主题或正文。 相反,它说它不识别这些字段

也有人知道如何将这些作为String传递给函数吗?

谢谢

1 个答案:

答案 0 :(得分:0)

所以看起来你的缺陷是缺少'?'在“主题”之前根据:http://support2.microsoft.com/default.aspx?scid=kb;en-us;181991

const string to{"firstmail@mail.com"};
const string cc{"ccmail@mail.com"};
const string subject{"TestEmail"};
const string body{"Hello%20World"};
const string test{"cmd /c OUTLOOK.EXE /c ipm.note /m \"" + to + "&cc=" + cc + "?subject=" + subject + "&body=" +  body + '"'};

cout << test;
system(test);

作为对代码的临时更改,您可以添加test。那会打印出一个字符串。在命令提示符中导航到OUTLOOK.exe的位置(我的是:C:\ Program Files(x86)\ Microsoft Office \ Office14)。然后输入打印出来的std::string test,删除应该运行的“cmd / c”前缀。如果在命令提示符中没有根据需要调整命令,则相应地调整代码。例如,我的命令如下所示:

  

OUTLOOK.exe / c ipm.note / m“firstmail@mail.com& cc = ccmail@mail.com?subject = TestEmail&amp; body = Hello%20World”