使用Mapi发送邮件并回复多封电子邮件
Send mail with Mapi with reply-to multiple emails
我正在使用C++中的MAPI库发送电子邮件。现在我需要我发送的电子邮件有一个回复设置为多封电子邮件,我只需要对一封电子邮件进行回复。
我已经读到,为了能够做到这一点,我需要使用对象FLATENTRYLIST(链接)和FLATENTRY(链接)。我的疑问是如何在FLATENTRYLIST中存储多个FLATENTRY对象。我在C++方面的经验不是很丰富,所以如果有人能帮助我,我会感激的。
提前感谢
Paulo
FLATENTRYLIST具有cEntries成员,用于确定列表中的条目数。您只需要将条目存储在abEntries数组中。
这是我开发的解决方案-http://www.codeproject.com/KB/IP/CMapiEx.aspx?msg=3959770#xx3959770xx
感谢德米特里的帮助。
当我将EntryID复制到FlatEntry时,我复制了错误的字节数。这是最后一个像符咒一样工作的代码。
BOOL CMAPIMessage::SetReplyTo(LPADRLIST lpAddrList)
{
HRESULT hRes = S_OK;
SPropValue pspvReply[1];
LPFLATENTRYLIST lpEntryList = NULL;
BOOL bResult = false;
CString m_strReplyToNames;
int cb = 0;
int displayNameTagID = -1;
int emailTagID = -1;
int entryIDTagID = -1;
int cbAllBytes = 0;
//Get all the EntryID's bytes to initalize the FLATENTRYLIST
for(unsigned j=0; j<lpAddrList->cEntries; j++)
{
for (unsigned i = 0; i < lpAddrList->aEntries[j].cValues; i++)
{
if (lpAddrList->aEntries[j].rgPropVals[i].ulPropTag == PR_ENTRYID)
{
entryIDTagID = i;
}
}
if (entryIDTagID >= 0)
{
int feBytes = CbNewFLATENTRY(lpAddrList->aEntries[j].rgPropVals[entryIDTagID].Value.bin.cb);
cbAllBytes += feBytes;
cbAllBytes += ((feBytes + 4 & ~3) - feBytes);
}
}
//Allocate a new FLATENTRYLIST with all flatentries bytes
cb = CbNewFLATENTRYLIST(cbAllBytes);
hRes = MAPIAllocateBuffer(cb, (LPVOID *)&lpEntryList);
if (FAILED(hRes))
{
bResult = false;
goto Cleanup;
}
ZeroMemory((VOID *)lpEntryList, cb);
// Copy the bits of the FLATENTRY into the FLATENTRYLIST.
lpEntryList->cEntries = lpAddrList->cEntries;
int countBytesAdded = 0;
for(unsigned j=0; j<lpAddrList->cEntries; j++)
{
for (unsigned i = 0; i < lpAddrList->aEntries[j].cValues; i++)
{
if (lpAddrList->aEntries[j].rgPropVals[i].ulPropTag == PR_TRANSMITABLE_DISPLAY_NAME)
{
displayNameTagID = i;
}
else if (lpAddrList->aEntries[j].rgPropVals[i].ulPropTag == PR_EMAIL_ADDRESS)
{
emailTagID = i;
}
else if (lpAddrList->aEntries[j].rgPropVals[i].ulPropTag == PR_ENTRYID)
{
entryIDTagID = i;
}
}
if ((emailTagID>=0) && (entryIDTagID>=0))
{
CString m_strReplyToName;
CString m_strReplyToEmail;
m_strReplyToEmail=lpAddrList->aEntries[j].rgPropVals[emailTagID].Value.lpszA;
if(displayNameTagID>=0)
m_strReplyToName=lpAddrList->aEntries[j].rgPropVals[displayNameTagID].Value.lpszA;
else
m_strReplyToName = m_strReplyToEmail;
m_strReplyToNames += (CString)m_strReplyToName + ";";
// Allocate a new FLATENTRY structure for the PR_REPLY_RECIPIENT_ENTRIES property
LPFLATENTRY lpReplyEntry = NULL;
cb = CbNewFLATENTRY(lpAddrList->aEntries[j].rgPropVals[entryIDTagID].Value.bin.cb);
hRes = MAPIAllocateBuffer(cb, (LPVOID *)&lpReplyEntry);
if (FAILED(hRes))
{
bResult = false;
goto Cleanup;
}
ZeroMemory((VOID *)lpReplyEntry, cb);
// Copy the bits of the entry id into the FLATENTRY structure
CopyMemory(lpReplyEntry->abEntry,
lpAddrList->aEntries[j].rgPropVals[entryIDTagID].Value.bin.lpb,
lpAddrList->aEntries[j].rgPropVals[entryIDTagID].Value.bin.cb);
lpReplyEntry->cb = lpAddrList->aEntries[j].rgPropVals[entryIDTagID].Value.bin.cb;
int missingBytes = 0;
int feBytes = CbFLATENTRY(lpReplyEntry);
missingBytes = ((feBytes + 4 & ~3) - feBytes);
//Copy each FLATENTRY to the abEntries, next to the previous added bytes
CopyMemory(lpEntryList->abEntries + countBytesAdded, lpReplyEntry, feBytes);
countBytesAdded += feBytes + missingBytes;
//Clean Memory
if (lpReplyEntry) MAPIFreeBuffer(lpReplyEntry);
}
displayNameTagID = -1;
emailTagID = -1;
entryIDTagID = -1;
}
lpEntryList->cbEntries = countBytesAdded;
pspvReply[0].ulPropTag = PR_REPLY_RECIPIENT_ENTRIES;
// Allocate memory in the lpb to hold the FLATENTRYLIST
hRes = MAPIAllocateBuffer(CbFLATENTRYLIST(lpEntryList), (LPVOID *)&pspvReply[0].Value.bin.lpb);
if (FAILED(hRes))
{
bResult = false;
goto Cleanup;
}
// Copy the memory into the SPropValue
CopyMemory(pspvReply[0].Value.bin.lpb,lpEntryList,CbFLATENTRYLIST(lpEntryList));
pspvReply[0].Value.bin.cb = CbFLATENTRYLIST(lpEntryList);
//Set the PR_REPLY_RECIPIENT_NAMES property with all names
SetPropertyString(PR_REPLY_RECIPIENT_NAMES, m_strReplyToNames);
// Set the property that contains the FLATENTRYLIST with the reply-to adresses to the message properties
hRes = Message()->SetProps(1,pspvReply,NULL);
if (FAILED(hRes))
{
bResult = false;
goto Cleanup;
}
bResult = true;
Cleanup:
if (lpEntryList) MAPIFreeBuffer(lpEntryList);
return bResult;
}
相关文章:
- 尝试从C++访问 UWP 的电子邮件邮件类会导致"REGDB_E_CLASSNOTREG类未注册"错误
- 如何使HTML5电子邮件验证正则表达式在C++中工作?
- Qt:使用'mailto:'打开用户的电子邮件客户端失败
- 电子邮件地址中的c++smtp服务器主机名
- 如何使用 c++ (curl) 发送电子邮件
- 在端口 587 (TLS) 上使用 CDO 发送电子邮件时出错
- 预览由Microsoft Outlook 对象库生成的电子邮件
- 如果不有效,如何重复用户输入电子邮件
- 使用REGEX进行电子邮件输入验证C
- 如何从 pjsip 发送电子邮件.是否有任何可用于发送电子邮件的默认方法
- 如何在使用 c++/COM 发送时在电子邮件中插入/嵌入图像文件(.png)
- 使用Regex验证电子邮件和电话字段QT
- 带有 TLS v. 1.2 和 SSL v.3 电子邮件客户端的 Boost.Asio 上下文:ssl3 警报意外消息
- 如何发送带有嵌入图片的电子邮件
- 如何提示用户在C++中输入正确的电子邮件地址格式
- 我在尝试使用 libquickmail 发送电子邮件时收到错误
- C 从电子邮件向量中删除
- 使用VC 应用中的VSTO ADDIN触发Outlook电子邮件附件的删除
- C 和卷曲,发送电子邮件时编码奇怪的字符
- 使用Mapi发送邮件并回复多封电子邮件