gpt4 book ai didi

C++ 通过 Outlook 发送 HTML 邮件

转载 作者:行者123 更新时间:2023-11-28 07:58:30 27 4
gpt4 key购买 nike

[目标]

基本 C++ 控制台应用程序需要能够通过 Outlook 2007(最小化运行)发送 HTML 电子邮件 - 不需要附件。此方法适用于纯文本,我不确定是否可以对其进行修改以适应 HTML 的要求。我在某处读到,也许您可​​以引用一个附件,它会变成正文。我只是不确定下一步该做什么。有什么建议吗?

[我目前拥有的]

BOOL SendMail(CHAR *lpszFrom, CHAR *lpszTo, CHAR *lpszSubject, CHAR *lpszMessage)
{
BOOL bSent = FALSE;

HINSTANCE hMAPI = ::LoadLibrary(_T("mapi32.dll"));
if(0==hMAPI) return bSent;

typedef ULONG (FAR PASCAL *PFN_MAPILogon)(ULONG,LPTSTR,LPTSTR,FLAGS,ULONG,LPLHANDLE);
typedef ULONG (FAR PASCAL *PFN_MAPISendMail)(LHANDLE,ULONG,lpMapiMessage,FLAGS,ULONG);
typedef ULONG (FAR PASCAL *PFN_MAPILogoff)(LHANDLE,ULONG,FLAGS,ULONG);

PFN_MAPILogon MAPILogon = (PFN_MAPILogon)::GetProcAddress(hMAPI,"MAPILogon");
PFN_MAPISendMail MAPISendMail = (PFN_MAPISendMail)::GetProcAddress(hMAPI,"MAPISendMail");
PFN_MAPILogoff MAPILogoff = (PFN_MAPILogoff)::GetProcAddress(hMAPI,"MAPILogoff");

const BOOL bFunctionsLoaded = (0!=MAPILogon)&&(0!=MAPISendMail)&&(0!=MAPILogoff);
ASSERT(bFunctionsLoaded);

if(bFunctionsLoaded)
{

LHANDLE session = 0;
VERIFY(SUCCESS_SUCCESS==MAPILogon(0,0,0,MAPI_NEW_SESSION,0,&session));
ASSERT(0!=session);

MapiRecipDesc recipient;
::ZeroMemory(&recipient,sizeof(recipient));
recipient.ulRecipClass = MAPI_TO;
recipient.lpszName = lpszTo;

MapiMessage message;
::ZeroMemory(&message,sizeof(message));
message.lpszSubject = lpszSubject;
message.lpszNoteText = lpszMessage;
message.nRecipCount = 1;
message.lpRecips = &recipient;

bSent = SUCCESS_SUCCESS == MAPISendMail(session,0,&message,0,0);

VERIFY(SUCCESS_SUCCESS==MAPILogoff(session,0,0,0));

}

::FreeLibrary(hMAPI);

return bSent;
}

由...调用

SendMail("from","to","subject","body");

最佳答案

看起来 MAPI 不适合 HTML 电子邮件。

http://support.microsoft.com/kb/268440

我已经通过 MFC 发送了 HTML 电子邮件,但那不是 MAPI。

关于C++ 通过 Outlook 发送 HTML 邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12113255/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com