Click here to Skip to main content
13,253,507 members (32,416 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 9 May 2007

Outlook2003 AddIN / Plugin Moving Items(Mail)

, 9 Jul 2007
Rate this:
Please Sign up or sign in to vote.
Whenever new mail is coming to inbox AddIN will move that mail to specific folder inside inbox.


For this article you should have basic knowledge of outlook AddIN.If you are beginner then go through my first basic article which will help you lot First artical Link .Outlook AddIN is moving unread marked item(mail)of inbox to some specific folder inside Oulook. AddIN is also moving mail when receiving new mail it is directly moving item to specific folder in outlook unknowingly of user. Moving item(mail) is very easy in VB but it is bit difficult in vc++ that's why I have added this article.

Using the code

You need to register DLL using regsvr32 "dll full path" command. If DLL is registered successfully then start outlook. Whenever you will be receiving new mail in inbox all unread marked mail will be move to folder "Hide_By_Chaitanya" this folder is created by program on OnStartupComplete. And then program is catching new mail event. Whenever new mail event is occurred it is calling OnNewMail method. This method is containing code for moving unread marked mail from Inbox to Hide_By_Chaitanya folder.

There are two main part of this code.

1. OnStartupComplete

    Outlook::_Application *spApplication;

    spApplication = m_spApp;

CComPtr <Outlook::_NameSpace> olNs;

    Outlook::MAPIFolder *spMapiFolderMove;

Outlook::_Folders *spFolderMove;

CComPtr <Outlook::MAPIFolder> spInboxFolder;

//Start a MAPI Session
// Taking session for doing activity on outlook
spApplication ->get_Session(&olNs);



CComVariant varFolderType1("IPF.Note");

BSTR bstr_temp1(OLESTR("Hold_By_chaitanya"));  //Name of folder

This much part of code is for creating new folder inside Inbox folder in outlook.

2. OnNewMail

        IDispatch *pDisp;
    IDispatch *pDisptemp;
    CComPtr <Outlook::_NameSpace> olNs;
    CComPtr<Outlook::_Items> spItems;
    Outlook::_Items *spUnReadedItems;
    Outlook::_MailItem *spMailItem;   
        Outlook::MAPIFolder *spMapiFolderMove;
    Outlook::_Folders *spFolderMove;
    CComPtr <Outlook::MAPIFolder> spInboxFolder;    

    //Start a MAPI Session
    Outlook::_Application *spOutlookApp; 

    spOutlookApp = m_spApp; 

    // Taking session for doing activity on outlook

    long count;
    spMapiFolderMove = NULL;


    BSTR bstrCompare(OLESTR("Hold_By_chaitanya"));
    BSTR bstrCompare2;


    char* lpszText1 = _com_util::ConvertBSTRToString(bstrCompare);
    char* lpszText2 = _com_util::ConvertBSTRToString(bstrCompare2);

        HRESULT hr = NULL;
    int i=0;
    while(i<count) //strcmpi(lpszText1,lpszText2) != 0)
        lpszText2 = _com_util::ConvertBSTRToString(bstrCompare2);
        if(strcmpi(lpszText1,lpszText2) == 0)

    _bstr_t bstrUnReadCondition(OLESTR("[UnRead] = true"));
//    Now count is changed and it contains unreaded mail count
    // Initialzing spMail so that i will not corrupt
    spMailItem = NULL;
    pDisp = NULL;
    CComVariant tempInt(1);
            tempInt.lVal = i+1; 

        if(pDisp != NULL)

            if(spMailItem != NULL)
This part of code is for moving unread marked mail from inbox to our created folder. You can also change folder name by changing name inside BSTR variable.

Points of Interest

You should search outlookspy on the net and install it this can help you to understand few things about outlook.


If you are facing any problem in understanding you need to go to basic of creating outlook AddIN. I have not included here basic steps of crating AddIN because of insufficient time. I can suggest you to go through my first article First artical Link where I have included basic thing and different links which can help you understanding basic of creation of outlook AddIN.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

chaitanya shah
Technical Lead Tata Consultancy Servcies
India India
I have experience in iOs, Objective C,Java,C++/Vc++ 6.0,vc.Net,MFC,ATL,COM,WTL.

You can contact me on if you have any query.

You may also be interested in...

Comments and Discussions

QuestionSounds interesting - screenshot / sample? Pin
Ralph9-Jul-07 23:24
memberRalph9-Jul-07 23:24 
AnswerRe: Sounds interesting - screenshot / sample? Pin
chaitanya shah14-Jul-07 7:06
memberchaitanya shah14-Jul-07 7:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 10 Jul 2007
Article Copyright 2007 by chaitanya shah
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid