How to catch a mail before it is sent

Joined
Jun 28, 2005
Messages
1
Reaction score
0
Hi everyone,

I have quite a big problem here : I try to create a C++ COM add-in for Outlook 2000. My goal is to add an information to a mail, then to sign the mail in a special way before it is sent.

I achieved adding the header to the mail, but I can't manage to catch the event SendItem. Someone could help me please ?

There is parts of my code :

// Connect.h : Declaration of the CConnect

#pragma once
#include "resource.h" // main symbols


extern _ATL_FUNC_INFO OnClickButtonInfo;
extern _ATL_FUNC_INFO OnMailSendInfo;

// CConnect
class ATL_NO_VTABLE CConnect :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CConnect, &CLSID_Connect>,

public IDispatchImpl<AddInDesignerObjects::_IDTExtensibility2, &AddInDesignerObjects::IID__IDTExtensibility2, &AddInDesignerObjects::LIBID_AddInDesignerObjects, 1, 0>,
public IDispEventSimpleImpl<1, CConnect, &__uuidof(Office::_CommandBarButtonEvents)>,
public IDispEventSimpleImpl<2, CConnect, &__uuidof(Outlook::ApplicationEvents)>
{
public:
typedef IDispEventSimpleImpl<1, CConnect, &__uuidof(Office::_CommandBarButtonEvents)> CommnandButton1Events;
typedef IDispEventSimpleImpl<2, CConnect, &__uuidof(Outlook::ApplicationEvents)> Application2Events;
CConnect()
{
}

DECLARE_REGISTRY_RESOURCEID(IDR_ADDIN)
DECLARE_NOT_AGGREGATABLE(CConnect)

BEGIN_COM_MAP(CConnect)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(AddInDesignerObjects::IDTExtensibility2)
END_COM_MAP()


BEGIN_SINK_MAP(CConnect)
SINK_ENTRY_INFO(
1,
__uuidof(Office::_CommandBarButtonEvents),
0x01,
OnClickButton,
&OnClickButtonInfo
)
SINK_ENTRY_INFO(
2,
__uuidof(Outlook::ApplicationEvents),
0x01,
OnMailSend,
&OnMailSendInfo
)
END_SINK_MAP()

DECLARE_PROTECT_FINAL_CONSTRUCT()

HRESULT FinalConstruct()
{
return S_OK;
}

void FinalRelease()
{
}

public:
//IDTExtensibility2 implementation:
STDMETHOD(OnConnection)(IDispatch * Application, AddInDesignerObjects::ext_ConnectMode ConnectMode, IDispatch *AddInInst, SAFEARRAY **custom);
STDMETHOD(OnDisconnection)(AddInDesignerObjects::ext_DisconnectMode RemoveMode, SAFEARRAY **custom );
STDMETHOD(OnAddInsUpdate)(SAFEARRAY **custom );
STDMETHOD(OnStartupComplete)(SAFEARRAY **custom );
STDMETHOD(OnBeginShutdown)(SAFEARRAY **custom );


void __stdcall OnClickButton(IDispatch * Ctrl,VARIANT_BOOL * CancelDefault);
void __stdcall OnMailSend(IDispatch * Ctrl,VARIANT_BOOL * CancelDefault);


private :
CComQIPtr <Outlook::_Application> spApp;
IDispatch *spApplication;
CComPtr<Office::_CommandBarButton> m_spButton;
};


OBJECT_ENTRY_AUTO(__uuidof(Connect), CConnect)



////////////
and there is the cpp file :

// Connect.cpp : Implementation of CConnect
#include "stdafx.h"
#include "AddIn.h"
#include "Connect.h"

#include "fenetreLabel.h"

extern CAddInModule _AtlModule;

_ATL_FUNC_INFO OnClickButtonInfo ={CC_STDCALL,VT_EMPTY,2,{VT_DISPATCH,VT_BYREF | VT_BOOL}};
_ATL_FUNC_INFO OnMailSendInfo ={CC_STDCALL,VT_EMPTY,2,{VT_DISPATCH,VT_BYREF | VT_BOOL}};

// When run, the Add-in wizard prepared the registry for the Add-in.
// At a later time, if the Add-in becomes unavailable for reasons such as:
// 1) You moved this project to a computer other than which is was originally created on.
// 2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
// 3) Registry corruption.
// you will need to re-register the Add-in by building the MyAddin21Setup project
// by right clicking the project in the Solution Explorer, then choosing install.

// CConnect
STDMETHODIMP CConnect::OnConnection(IDispatch *pApplication, AddInDesignerObjects::ext_ConnectMode ConnectMode, IDispatch *pAddInInst, SAFEARRAY ** /*custom*/ )
{
spApplication = pApplication;

CComPtr <Office::_CommandBars> spCmdBars;
CComPtr <Office::CommandBar> spCmdBar;



CComQIPtr <Outlook::_Application> spApp(pApplication);
ATLASSERT(spApp);

CComPtr<Outlook::_Explorer> spExplorer;
spExplorer = spApp->ActiveExplorer();

HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);
if (FAILED(hr)) {
return hr;
}

ATLASSERT(spCmdBars);

CComVariant vName("My nice add-in");
CComPtr <Office::CommandBar> spNewCmdBar;

CComVariant vPos(1);

CComVariant vTemp(VARIANT_TRUE);
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);

spCmdBars->Add(vName, vPos, vEmpty, vTemp, &spNewCmdBar);


CComPtr <Office::CommandBarControls> spBarControls;
spNewCmdBar->get_Controls(&spBarControls);
ATLASSERT(spBarControls);

CComVariant vToolBarType(1);
CComVariant vShow(VARIANT_TRUE);

CComPtr <Office::CommandBarControl> spNewBar;

spBarControls->Add(vToolBarType, vEmpty, vEmpty, vEmpty, vShow, &spNewBar);
ATLASSERT(spNewBar);

CComQIPtr <Office::_CommandBarButton> spCmdButton(spNewBar);
ATLASSERT(spCmdButton);

HBITMAP hBmp = (HBITMAP)::LoadImage(_AtlModule.GetResourceInstance(), MAKEINTRESOURCE(IDB_BITMAP_ICONE_LABEL), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);

::OpenClipboard(NULL);
::EmptyClipboard();
::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
::CloseClipboard();
::DeleteObject(hBmp);

spCmdButton->put_Style(Office::msoButtonIconAndCaption);

hr = spCmdButton->PasteFace();
if (FAILED(hr)) {
return hr;
}

spCmdButton->put_Visible(VARIANT_TRUE);
spCmdButton->put_Caption(OLESTR("Mail with header"));
spCmdButton->put_Enabled(VARIANT_TRUE);
spCmdButton->put_TooltipText(OLESTR("Adds a special header to a mail"));
spCmdButton->put_Tag(OLESTR("Marked mail !!"));

spNewCmdBar->put_Visible(VARIANT_TRUE);

m_spButton = spCmdButton;


CommnandButton1Events::DispEventAdvise((IDispatch*)m_spButton);

////////////////////////////

Application2Events::DispEventAdvise((IDispatch*)spApp);


return S_OK;
}

STDMETHODIMP CConnect::OnDisconnection(AddInDesignerObjects::ext_DisconnectMode /*RemoveMode*/, SAFEARRAY ** /*custom*/ )
{

CommnandButton1Events::DispEventUnadvise((IDispatch*)m_spButton);
Application2Events::DispEventUnadvise((IDispatch*)spApp);

return S_OK;
}

STDMETHODIMP CConnect::OnAddInsUpdate (SAFEARRAY ** /*custom*/ )
{
return S_OK;
}

STDMETHODIMP CConnect::OnStartupComplete (SAFEARRAY ** /*custom*/ )
{
return S_OK;
}

STDMETHODIMP CConnect::OnBeginShutdown (SAFEARRAY ** /*custom*/ )
{
return S_OK;
}



void __stdcall CConnect::OnClickButton(IDispatch* Ctrl,VARIANT_BOOL * CancelDefault) {

PluginOutlookCpp::fenetreLabel * fLabel;
fLabel = new PluginOutlookCpp::fenetreLabel(spApplication);

fLabel->ouvrir();



}


void __stdcall CConnect::OnMailSend(IDispatch* Ctrl,VARIANT_BOOL * CancelDefault) {

MessageBox(NULL, "Mail is being sent !","Advertisement", MB_OK);



}







Thanks a lot for your help !!!
 
Back
Top