选中一个文件按右键就可以用Outlook发送,请问用程序应如何实现的?如果在已知邮件信息(接收人、标题、正文……)应如何才能避免撰写新邮件进而直接用Outlook将文件作为附件发送?恳请指点:思路、想法、程序都可。在线恭候,谢谢!
解决方案 »
- 我是新手,我只想问一个小问题
- 我用CPropSheet做了一个属性表单。为什么我重载CPropSheet::OnClose()时不响应
- 非队列消息,GetMessage/PeekMessage是如何接受到的?
- 在主框架CPP中引入视图头文件后,出现如下错误
- 急!请高手指点:当个对话框窗口的尺寸发生改变时,如何调整按扭在对话框窗口中相对于窗口的位置?
- USE_CONVERSION 中文乱码,怎么解决
- 挂起,恢复进程
- 谁有ACTIVE控件电子书?
- 对HTML Help 帮助制作工具有兴趣的兄弟请进
- 请问.Dat 和 mpegI文件有什么不同,怎样互相转换。
- 为什么我的VC编译是只报几个错误却不指出错误位置,让我找不到错误的地方,无法查错。
- 这句竟然不对???HBITMAP hBmp = (HBITMAP)::LoadImage( AfxGetInstanceHandle(),"F:\\1.BMP", IMAGE_BITMAP, 0,0, LR_CREATEDIBSECTIO
我在WORD的下实现过,
不过还不完善
我大略查了一下MAPI,但似乎多数例子都是用其独立发送Mail而不是与Outlook结合使用,我了解的很肤浅,恳请老兄多多指点一二。To sunsuny(陽光之子):
谢谢!
1。做一个shell扩展,ContextMenu
2。引入Outlook的tlb,会产生一个包装类,实例化对象,调用相应成员函数处理。注意要检测outlook是否配置过,否则如果从未使用过,出现配置界面,是比较没水准的情况。
您的指点给了我一个方向,谢谢!但对于shell扩展和包装类我还是一片空白,还请详细指点一下具体的方向(应查资料或步骤),不胜感激。
To ExitWin(ExitWin) :
能否再详细一点?
///////mapi.h
class CIMapi
{
public:
CIMapi();
~CIMapi(); enum errorCodes
{
IMAPI_SUCCESS = 0,
IMAPI_LOADFAILED,
IMAPI_INVALIDDLL,
IMAPI_FAILTO,
IMAPI_FAILCC,
IMAPI_FAILATTACH
};// Attributes
void Subject(LPCTSTR subject) { m_message.lpszSubject = (LPTSTR) subject; }
void Text(LPCTSTR text) { m_text = text; } UINT Error();
void From(LPCTSTR from) { m_from.lpszName = (LPTSTR) from; } static BOOL HasEmail();// Operations
BOOL To(LPCTSTR recip);
BOOL Cc(LPCTSTR recip);
BOOL Attach(LPCTSTR path, LPCTSTR name = NULL);
BOOL Send(ULONG flags = 0);private:
BOOL AllocNewTo(); MapiMessage m_message;
MapiRecipDesc m_from;
UINT m_error;
CString m_text; ULONG (PASCAL *m_lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
static HINSTANCE m_hInstMail;
static BOOL m_isMailAvail;
};
/////mapi.cpp
#include "stdafx.h"
#include <mapi.h>
#include "imapi.h"HINSTANCE CIMapi::m_hInstMail = (HINSTANCE) NULL;
BOOL CIMapi::m_isMailAvail = (BOOL) -1;CIMapi::CIMapi()
{
m_error = 0; // Initially error free memset(&m_message, 0, sizeof(MapiMessage));
memset(&m_from, 0, sizeof(MapiRecipDesc));
m_message.lpOriginator = &m_from;
m_from.ulRecipClass = MAPI_ORIG; if (m_hInstMail == (HINSTANCE) NULL) // Load the MAPI dll
m_hInstMail = ::LoadLibraryA("MAPI32.DLL"); if (m_hInstMail == (HINSTANCE) NULL)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD);
m_error = IMAPI_LOADFAILED;
return;
} ASSERT(m_hInstMail != (HINSTANCE) NULL); // Now get the pointer to the send function
(FARPROC&) m_lpfnSendMail = GetProcAddress(m_hInstMail, "MAPISendMail"); if (m_lpfnSendMail == NULL)
{
AfxMessageBox(AFX_IDP_INVALID_MAPI_DLL);
m_error = IMAPI_INVALIDDLL;
return;
} ASSERT(m_lpfnSendMail != NULL);
}CIMapi::~CIMapi()
{
if (m_hInstMail != (HINSTANCE) NULL)
::FreeLibrary(m_hInstMail); m_hInstMail = (HINSTANCE) NULL;
free(m_message.lpFiles);
free(m_message.lpRecips);
}BOOL CIMapi::HasEmail()
{
if (m_isMailAvail == (BOOL) -1)
m_isMailAvail = ::GetProfileInt(_T("MAIL"), _T("MAPI"), 0) != 0 && SearchPath(NULL, _T("MAPI32.DLL"), NULL, 0, NULL, NULL) != 0; return m_isMailAvail;
}UINT CIMapi::Error()
{
UINT temp = m_error; m_error = IMAPI_SUCCESS;
return temp;
}BOOL CIMapi::AllocNewTo()
{
// Allocate a new MapiRecipDesc structure and initialise it to all zeros
m_message.lpRecips = (MapiRecipDesc *) realloc(m_message.lpRecips, (m_message.nRecipCount + 1) * sizeof(MapiRecipDesc));
memset(&m_message.lpRecips[m_message.nRecipCount], 0, sizeof(MapiRecipDesc)); ASSERT(m_message.lpRecips);
return m_message.lpRecips != (MapiRecipDesc *) NULL;
}BOOL CIMapi::To(LPCTSTR recip)
{
if (AllocNewTo())
{
// We succeeded in allocating a new recipient record
m_message.lpRecips[m_message.nRecipCount].lpszName = (LPTSTR) malloc(strlen(recip) + 1);
strcpy(m_message.lpRecips[m_message.nRecipCount].lpszName, recip);
m_message.lpRecips[m_message.nRecipCount].ulRecipClass = MAPI_TO;
m_message.nRecipCount++;
return TRUE;
} m_error = IMAPI_FAILTO;
return FALSE;
}BOOL CIMapi::Cc(LPCTSTR recip)
{
if (AllocNewTo())
{
// We succeeded in allocating a new recipient record
m_message.lpRecips[m_message.nRecipCount].lpszName = (LPTSTR) malloc(strlen(recip) + 1);
strcpy(m_message.lpRecips[m_message.nRecipCount].lpszName, recip);
m_message.lpRecips[m_message.nRecipCount].ulRecipClass = MAPI_CC;
m_message.nRecipCount++;
return TRUE;
} m_error = IMAPI_FAILCC;
return FALSE;
}BOOL CIMapi::Attach(LPCTSTR path, LPCTSTR name)
{
// Add a new attachment record
m_message.lpFiles = (MapiFileDesc *) realloc(m_message.lpFiles, (m_message.nFileCount + 1) * sizeof(MapiFileDesc));
memset(&m_message.lpFiles[m_message.nFileCount], 0, sizeof(MapiFileDesc)); ASSERT(m_message.lpFiles);
if (m_message.lpFiles == (MapiFileDesc *) NULL)
{
m_error = IMAPI_FAILATTACH;
return FALSE;
} m_message.lpFiles[m_message.nFileCount].lpszPathName = (LPTSTR) malloc(strlen(path) + 1);
strcpy(m_message.lpFiles[m_message.nFileCount].lpszPathName, path); if (name != (LPCTSTR) NULL)
{
m_message.lpFiles[m_message.nFileCount].lpszFileName = (LPTSTR) malloc(strlen(name) + 1);
strcpy(m_message.lpFiles[m_message.nFileCount].lpszFileName, name);
} m_message.nFileCount++;
return TRUE;
}BOOL CIMapi::Send(ULONG flags)
{
CWaitCursor wait;
int offset = m_text.GetLength(); // Add 1 space per attachment at the end of the body text.
m_text += CString(' ', m_message.nFileCount); // Set each attachment to replace one of the added spaces at the end of the body text.
for (UINT i = 0; i < m_message.nFileCount; i++)
m_message.lpFiles[i].nPosition = offset++; m_message.lpszNoteText = (LPTSTR) (LPCTSTR) m_text; // Set the body text // prepare for modal dialog box
AfxGetApp()->EnableModeless(FALSE);
HWND hWndTop;
CWnd* pParentWnd = CWnd::GetSafeOwner(NULL, &hWndTop); // some extra precautions are required to use MAPISendMail as it
// tends to enable the parent window in between dialogs (after
// the login dialog, but before the send note dialog).
pParentWnd->SetCapture();
::SetFocus(NULL);
pParentWnd->m_nFlags |= WF_STAYDISABLED; int nError = m_lpfnSendMail(0, (ULONG) pParentWnd->GetSafeHwnd(), &m_message, MAPI_LOGON_UI | flags, 0); // after returning from the MAPISendMail call, the window must
// be re-enabled and focus returned to the frame to undo the workaround
// done before the MAPI call.
::ReleaseCapture();
pParentWnd->m_nFlags &= ~WF_STAYDISABLED; pParentWnd->EnableWindow(TRUE);
::SetActiveWindow(NULL);
pParentWnd->SetActiveWindow();
pParentWnd->SetFocus();
if (hWndTop != NULL)
::EnableWindow(hWndTop, TRUE);
AfxGetApp()->EnableModeless(TRUE); // Now free malloced recipients
for (i = 0; i < m_message.nRecipCount; i++)
free(m_message.lpRecips[i].lpszName); // Then free malloced attachments
for (i = 0; i < m_message.nFileCount; i++)
{
free(m_message.lpFiles[i].lpszPathName);
free(m_message.lpFiles[i].lpszFileName);
} if (nError != SUCCESS_SUCCESS && nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_SEND);
return FALSE;
} return TRUE;
}
//////调用
CIMapi mail;
mail.To("[email protected]"); // 设置接收者姓名
//mail.To("[email protected]");// 第二个接收者
mail.Cc("[email protected]"); // 抄送接收者
//mail.From("[email protected]"); // 发送者标识(不是必须的,因为MAPI将为你添加这个标识)
mail.Subject("Test Email"); // 这封信的主题
///mail.Attach("somefilename"); // 附加一个文件
//mail.Attach("someotherfile", "different_name_for_recipient"); // 附加另外一个文件,但是在邮件中给它指定一个不同的名字
// 把文本串放入信体中
mail.Text("Body text for this email"); // 设置信体文本
mail.Send(); //
///////mapi.h
class CIMapi
{
public:
CIMapi();
~CIMapi(); enum errorCodes
{
IMAPI_SUCCESS = 0,
IMAPI_LOADFAILED,
IMAPI_INVALIDDLL,
IMAPI_FAILTO,
IMAPI_FAILCC,
IMAPI_FAILATTACH
};// Attributes
void Subject(LPCTSTR subject) { m_message.lpszSubject = (LPTSTR) subject; }
void Text(LPCTSTR text) { m_text = text; } UINT Error();
void From(LPCTSTR from) { m_from.lpszName = (LPTSTR) from; } static BOOL HasEmail();// Operations
BOOL To(LPCTSTR recip);
BOOL Cc(LPCTSTR recip);
BOOL Attach(LPCTSTR path, LPCTSTR name = NULL);
BOOL Send(ULONG flags = 0);private:
BOOL AllocNewTo(); MapiMessage m_message;
MapiRecipDesc m_from;
UINT m_error;
CString m_text; ULONG (PASCAL *m_lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
static HINSTANCE m_hInstMail;
static BOOL m_isMailAvail;
};
/////mapi.cpp
#include "stdafx.h"
#include <mapi.h>
#include "imapi.h"HINSTANCE CIMapi::m_hInstMail = (HINSTANCE) NULL;
BOOL CIMapi::m_isMailAvail = (BOOL) -1;CIMapi::CIMapi()
{
m_error = 0; // Initially error free memset(&m_message, 0, sizeof(MapiMessage));
memset(&m_from, 0, sizeof(MapiRecipDesc));
m_message.lpOriginator = &m_from;
m_from.ulRecipClass = MAPI_ORIG; if (m_hInstMail == (HINSTANCE) NULL) // Load the MAPI dll
m_hInstMail = ::LoadLibraryA("MAPI32.DLL"); if (m_hInstMail == (HINSTANCE) NULL)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD);
m_error = IMAPI_LOADFAILED;
return;
} ASSERT(m_hInstMail != (HINSTANCE) NULL); // Now get the pointer to the send function
(FARPROC&) m_lpfnSendMail = GetProcAddress(m_hInstMail, "MAPISendMail"); if (m_lpfnSendMail == NULL)
{
AfxMessageBox(AFX_IDP_INVALID_MAPI_DLL);
m_error = IMAPI_INVALIDDLL;
return;
} ASSERT(m_lpfnSendMail != NULL);
}CIMapi::~CIMapi()
{
if (m_hInstMail != (HINSTANCE) NULL)
::FreeLibrary(m_hInstMail); m_hInstMail = (HINSTANCE) NULL;
free(m_message.lpFiles);
free(m_message.lpRecips);
}BOOL CIMapi::HasEmail()
{
if (m_isMailAvail == (BOOL) -1)
m_isMailAvail = ::GetProfileInt(_T("MAIL"), _T("MAPI"), 0) != 0 && SearchPath(NULL, _T("MAPI32.DLL"), NULL, 0, NULL, NULL) != 0; return m_isMailAvail;
}UINT CIMapi::Error()
{
UINT temp = m_error; m_error = IMAPI_SUCCESS;
return temp;
}BOOL CIMapi::AllocNewTo()
{
// Allocate a new MapiRecipDesc structure and initialise it to all zeros
m_message.lpRecips = (MapiRecipDesc *) realloc(m_message.lpRecips, (m_message.nRecipCount + 1) * sizeof(MapiRecipDesc));
memset(&m_message.lpRecips[m_message.nRecipCount], 0, sizeof(MapiRecipDesc)); ASSERT(m_message.lpRecips);
return m_message.lpRecips != (MapiRecipDesc *) NULL;
}BOOL CIMapi::To(LPCTSTR recip)
{
if (AllocNewTo())
{
// We succeeded in allocating a new recipient record
m_message.lpRecips[m_message.nRecipCount].lpszName = (LPTSTR) malloc(strlen(recip) + 1);
strcpy(m_message.lpRecips[m_message.nRecipCount].lpszName, recip);
m_message.lpRecips[m_message.nRecipCount].ulRecipClass = MAPI_TO;
m_message.nRecipCount++;
return TRUE;
} m_error = IMAPI_FAILTO;
return FALSE;
}BOOL CIMapi::Cc(LPCTSTR recip)
{
if (AllocNewTo())
{
// We succeeded in allocating a new recipient record
m_message.lpRecips[m_message.nRecipCount].lpszName = (LPTSTR) malloc(strlen(recip) + 1);
strcpy(m_message.lpRecips[m_message.nRecipCount].lpszName, recip);
m_message.lpRecips[m_message.nRecipCount].ulRecipClass = MAPI_CC;
m_message.nRecipCount++;
return TRUE;
} m_error = IMAPI_FAILCC;
return FALSE;
}BOOL CIMapi::Attach(LPCTSTR path, LPCTSTR name)
{
// Add a new attachment record
m_message.lpFiles = (MapiFileDesc *) realloc(m_message.lpFiles, (m_message.nFileCount + 1) * sizeof(MapiFileDesc));
memset(&m_message.lpFiles[m_message.nFileCount], 0, sizeof(MapiFileDesc)); ASSERT(m_message.lpFiles);
if (m_message.lpFiles == (MapiFileDesc *) NULL)
{
m_error = IMAPI_FAILATTACH;
return FALSE;
} m_message.lpFiles[m_message.nFileCount].lpszPathName = (LPTSTR) malloc(strlen(path) + 1);
strcpy(m_message.lpFiles[m_message.nFileCount].lpszPathName, path); if (name != (LPCTSTR) NULL)
{
m_message.lpFiles[m_message.nFileCount].lpszFileName = (LPTSTR) malloc(strlen(name) + 1);
strcpy(m_message.lpFiles[m_message.nFileCount].lpszFileName, name);
} m_message.nFileCount++;
return TRUE;
}BOOL CIMapi::Send(ULONG flags)
{
CWaitCursor wait;
int offset = m_text.GetLength(); // Add 1 space per attachment at the end of the body text.
m_text += CString(' ', m_message.nFileCount); // Set each attachment to replace one of the added spaces at the end of the body text.
for (UINT i = 0; i < m_message.nFileCount; i++)
m_message.lpFiles[i].nPosition = offset++; m_message.lpszNoteText = (LPTSTR) (LPCTSTR) m_text; // Set the body text // prepare for modal dialog box
AfxGetApp()->EnableModeless(FALSE);
HWND hWndTop;
CWnd* pParentWnd = CWnd::GetSafeOwner(NULL, &hWndTop); // some extra precautions are required to use MAPISendMail as it
// tends to enable the parent window in between dialogs (after
// the login dialog, but before the send note dialog).
pParentWnd->SetCapture();
::SetFocus(NULL);
pParentWnd->m_nFlags |= WF_STAYDISABLED; int nError = m_lpfnSendMail(0, (ULONG) pParentWnd->GetSafeHwnd(), &m_message, MAPI_LOGON_UI | flags, 0); // after returning from the MAPISendMail call, the window must
// be re-enabled and focus returned to the frame to undo the workaround
// done before the MAPI call.
::ReleaseCapture();
pParentWnd->m_nFlags &= ~WF_STAYDISABLED; pParentWnd->EnableWindow(TRUE);
::SetActiveWindow(NULL);
pParentWnd->SetActiveWindow();
pParentWnd->SetFocus();
if (hWndTop != NULL)
::EnableWindow(hWndTop, TRUE);
AfxGetApp()->EnableModeless(TRUE); // Now free malloced recipients
for (i = 0; i < m_message.nRecipCount; i++)
free(m_message.lpRecips[i].lpszName); // Then free malloced attachments
for (i = 0; i < m_message.nFileCount; i++)
{
free(m_message.lpFiles[i].lpszPathName);
free(m_message.lpFiles[i].lpszFileName);
} if (nError != SUCCESS_SUCCESS && nError != MAPI_USER_ABORT && nError != MAPI_E_LOGIN_FAILURE)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_SEND);
return FALSE;
} return TRUE;
}
//////调用
CIMapi mail;
mail.To("[email protected]"); // 设置接收者姓名
//mail.To("[email protected]");// 第二个接收者
mail.Cc("[email protected]"); // 抄送接收者
//mail.From("[email protected]"); // 发送者标识(不是必须的,因为MAPI将为你添加这个标识)
mail.Subject("Test Email"); // 这封信的主题
///mail.Attach("somefilename"); // 附加一个文件
//mail.Attach("someotherfile", "different_name_for_recipient"); // 附加另外一个文件,但是在邮件中给它指定一个不同的名字
// 把文本串放入信体中
mail.Text("Body text for this email"); // 设置信体文本
mail.Send(); //
太感谢了!努力实验中…………