我正在我的应用程序中实现“打印和电子邮件”功能,并使用MAPISendMail启动默认电子邮件客户端,并预先选择了文件附件。我希望能够自动填充“收件人”字段,但我在MapiMessage结构中找不到该选项。主题,正文,附件有选项,但不适用于“收件人”字段。
有没有办法使用MAPISendMail填充“收件人”字段?
答案 0 :(得分:1)
我找到了答案,MapiMessage结构中有一个收件人字段。这里是我在http://www.experts-exchange.com/Programming/Microsoft_Development/A_1820-Sending-Email-with-MAPI.html找到的一些示例代码,用于说明如何填写收件人字段:
BOOL SendMail(LPCSTR lpszSubject, LPCSTR lpszTo,
LPCSTR lpszName, LPCSTR lpszText)
{
HINSTANCE hMAPI = ::LoadLibrary(L"mapi32.dll");
LPMAPISENDMAIL lpfnMAPISendMail =
(LPMAPISENDMAIL)::GetProcAddress(hMAPI, "MAPISendMail");
char szTo[MAX_PATH] = { 0 };
strcat_s(szTo, lpszTo);
char szName[MAX_PATH] = { 0 };
strcat_s(szName, lpszName);
MapiRecipDesc recipient[1] = { 0 };
recipient[0].ulRecipClass = MAPI_TO;
recipient[0].lpszAddress = szTo;
recipient[0].lpszName = szName;
char szSubject[MAX_PATH] = { 0 };
strcat_s(szSubject, lpszSubject);
char szText[MAX_PATH] = { 0 };
strcat_s(szText, lpszText);
MapiMessage MAPImsg = { 0 };
MAPImsg.lpszSubject = szSubject;
MAPImsg.lpRecips = recipient;
MAPImsg.nRecipCount = 1;
MAPImsg.lpszNoteText = szText;
ULONG nSent = lpfnMAPISendMail(0, 0,
&MAPImsg, MAPI_LOGON_UI | MAPI_DIALOG, 0);
FreeLibrary(hMAPI);
return (nSent == SUCCESS_SUCCESS || nSent == MAPI_E_USER_ABORT);
}