outlook编程问题 怎么在点添加附件的时候截取消息?发送的时候截取也行我就是想替换掉它将要发送的文件。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 为什么Attachments.Add 说找不到指定路径啊?有会的吗? - -就是CComPtr<_MailItem> pMailItem; Item->QueryInterface(__uuidof(_MailItem), (void**)&pMailItem); HRESULT h = S_FALSE; do { if(!pMailItem) break; Attachments* pAttachments; Attachment* pAttachment; long lAttachmentCounts = 0; h = pMailItem->get_Attachments(&pAttachments); h = pAttachments->get_Count(&lAttachmentCounts); TCHAR msg[MAX_PATH] = {0}; _stprintf(msg, _T("item count = %d"), (int)lAttachmentCounts); ::OutputDebugString(msg); for(int i = 1; i <= lAttachmentCounts; i++) { pAttachment = NULL; VARIANT index; index.vt = VT_I4; index.lVal = i; pAttachments->Item(index, &pAttachment); h = pAttachment->SaveAsFile(_T("c:\\123123.txt")); ::OutputDebugString(_T("save succeeded!")); VARIANT vSource; vSource.vt = VT_BSTR; vSource.bstrVal = _T("c:/123123.txt"); VARIANT vType; vType.vt = VT_INT; int nn = sizeof(OlAttachmentType); h = pAttachment->get_Type((OlAttachmentType*)&vType.intVal); memset(msg, 0, MAX_PATH); _stprintf(msg, _T("type = %d"), vType.intVal); ::OutputDebugString(msg); VARIANT vPos; vPos = vtMissing; /*vPos.vt = VT_I4; h = pAttachment->get_Position(&vPos.lVal);*/ memset(msg, 0, MAX_PATH); _stprintf(msg, _T("position = %d"), vPos.lVal); ::OutputDebugString(msg); VARIANT vDisplayName; vDisplayName = vtMissing; /*vDisplayName.vt = VT_BSTR; vDisplayName.bstrVal = _T("123123");*/ if(pMailItem->Save() == S_FALSE) break; h = pAttachments->Remove(index.lVal); if(h == S_FALSE) break; h = pMailItem->Save(); ::OutputDebugString(_T("Remove succeeded!")); h = pMailItem->put_Body(BSTR(_T("xxxxxxxxx"))); h = pMailItem->Save(); h = pAttachments->Add(vSource, vType, vPos, vDisplayName, &pAttachment);pAttachments->Add(vSource, vType, vPos, vDisplayName, &pAttachment)这个提示找不到路径 VARIANT vSource; vSource.vt = VT_BSTR; vSource.bstrVal = _T("c:/123123.txt");这个就是绝对路径吧我看MSDN有c#和vb的代码就是没有c++的晕啊 private void SendSalesReport(){ Outlook.MailItem mail = Application.CreateItem( Outlook.OlItemType.olMailItem) as Outlook.MailItem; mail.Subject = "Quarterly Sales Report FY06 Q4"; Outlook.AddressEntry currentUser = Application.Session.CurrentUser.AddressEntry; if (currentUser.Type == "EX") { Outlook.ExchangeUser manager = currentUser.GetExchangeUser().GetExchangeUserManager(); // Add recipient using display name, alias, or smtp address mail.Recipients.Add(manager.PrimarySmtpAddress); mail.Recipients.ResolveAll(); mail.Attachments.Add(@"c:\sales reports\fy06q4.xlsx", Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing); mail.Send(); }} CPropertySheet的构造函数第一个参数是UINT时,报错;为LPCTSTR时,正确。求解 简单问题,求救,200高分相送! vc2005如何使编译(链接)时产生的map文件包含行号信息? 关于排序问题 没有可用分,专门办? mfc 视图背景图片刷新问题 ShellExecute的参数怎么设置? 请问编写dll程序的时候,dll文件和exe文件 入门以后该何去何从? 免费软件,程序员的悲哀! 怎么让字体放大后不出现锯齿 vc 6.0如何调用gdi+加??
有会的吗?
就是
CComPtr<_MailItem> pMailItem;
Item->QueryInterface(__uuidof(_MailItem), (void**)&pMailItem); HRESULT h = S_FALSE;
do
{
if(!pMailItem) break;
Attachments* pAttachments;
Attachment* pAttachment;
long lAttachmentCounts = 0; h = pMailItem->get_Attachments(&pAttachments);
h = pAttachments->get_Count(&lAttachmentCounts); TCHAR msg[MAX_PATH] = {0};
_stprintf(msg, _T("item count = %d"), (int)lAttachmentCounts);
::OutputDebugString(msg); for(int i = 1; i <= lAttachmentCounts; i++)
{
pAttachment = NULL;
VARIANT index;
index.vt = VT_I4;
index.lVal = i;
pAttachments->Item(index, &pAttachment); h = pAttachment->SaveAsFile(_T("c:\\123123.txt"));
::OutputDebugString(_T("save succeeded!")); VARIANT vSource;
vSource.vt = VT_BSTR;
vSource.bstrVal = _T("c:/123123.txt"); VARIANT vType;
vType.vt = VT_INT;
int nn = sizeof(OlAttachmentType);
h = pAttachment->get_Type((OlAttachmentType*)&vType.intVal); memset(msg, 0, MAX_PATH);
_stprintf(msg, _T("type = %d"), vType.intVal);
::OutputDebugString(msg); VARIANT vPos;
vPos = vtMissing;
/*vPos.vt = VT_I4;
h = pAttachment->get_Position(&vPos.lVal);*/ memset(msg, 0, MAX_PATH);
_stprintf(msg, _T("position = %d"), vPos.lVal);
::OutputDebugString(msg); VARIANT vDisplayName;
vDisplayName = vtMissing;
/*vDisplayName.vt = VT_BSTR;
vDisplayName.bstrVal = _T("123123");*/ if(pMailItem->Save() == S_FALSE) break;
h = pAttachments->Remove(index.lVal);
if(h == S_FALSE) break;
h = pMailItem->Save();
::OutputDebugString(_T("Remove succeeded!")); h = pMailItem->put_Body(BSTR(_T("xxxxxxxxx"))); h = pMailItem->Save();
h = pAttachments->Add(vSource, vType, vPos, vDisplayName, &pAttachment);
pAttachments->Add(vSource, vType, vPos, vDisplayName, &pAttachment)这个提示找不到路径
vSource.vt = VT_BSTR;
vSource.bstrVal = _T("c:/123123.txt");这个就是绝对路径吧
我看MSDN有c#和vb的代码
就是没有c++的
晕啊
private void SendSalesReport()
{
Outlook.MailItem mail = Application.CreateItem(
Outlook.OlItemType.olMailItem) as Outlook.MailItem;
mail.Subject = "Quarterly Sales Report FY06 Q4";
Outlook.AddressEntry currentUser =
Application.Session.CurrentUser.AddressEntry;
if (currentUser.Type == "EX")
{
Outlook.ExchangeUser manager =
currentUser.GetExchangeUser().GetExchangeUserManager();
// Add recipient using display name, alias, or smtp address
mail.Recipients.Add(manager.PrimarySmtpAddress);
mail.Recipients.ResolveAll();
mail.Attachments.Add(@"c:\sales reports\fy06q4.xlsx",
Outlook.OlAttachmentType.olByValue, Type.Missing,
Type.Missing);
mail.Send();
}
}