Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get outlook attachment event?

How to get outlook attachment event?

Scheduled Pinned Locked Moved C / C++ / MFC
jsonhelptutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SNI
    wrote on last edited by
    #1

    Hi, I have an application which uses ShellExecuteEx function to launch Outlook and attaching file. ************************************************************ shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ; shExecInfo.hwnd = NULL; shExecInfo.lpVerb = "open"; shExecInfo.lpFile = "outlook"; shExecInfo.lpParameters = "C:\Test.doc"; shExecInfo.lpDirectory = NULL; shExecInfo.nShow = SW_MAXIMIZE; shExecInfo.hInstApp = NULL; ShellExecuteEx(&shExecInfo); ************************************************************ I am using this functionality in my app ins such a way that once file attached i am proceeding with other functionality. But my problem is before file get attached my next step of application get executed.I want to get event or information that outlook is launched and file is get attached so that i can synchronize the functionality. Please let me know how we can get the file attached event in outlook. Is it possible by using other API's like CreateProcess...etc.... Pls suggest. THanks

    SNI

    S 1 Reply Last reply
    0
    • S SNI

      Hi, I have an application which uses ShellExecuteEx function to launch Outlook and attaching file. ************************************************************ shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ; shExecInfo.hwnd = NULL; shExecInfo.lpVerb = "open"; shExecInfo.lpFile = "outlook"; shExecInfo.lpParameters = "C:\Test.doc"; shExecInfo.lpDirectory = NULL; shExecInfo.nShow = SW_MAXIMIZE; shExecInfo.hInstApp = NULL; ShellExecuteEx(&shExecInfo); ************************************************************ I am using this functionality in my app ins such a way that once file attached i am proceeding with other functionality. But my problem is before file get attached my next step of application get executed.I want to get event or information that outlook is launched and file is get attached so that i can synchronize the functionality. Please let me know how we can get the file attached event in outlook. Is it possible by using other API's like CreateProcess...etc.... Pls suggest. THanks

      SNI

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      To do this, I suspect you need to interface to Outlook using it's COM object model. I don't think ShellExecuteEx will cut it. This article[^] shows how to talk to Outlook using Javascript. C++ is more involved - to get anywhere, you probably want to be using #import with Outlook's type library - use #import "progid:Outlook.Application" auto_search to get VC++ to generate classes for the Outlook object model. Alternatively, this article[^] tells you how to do Office Automation with COM without using #import.

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      S 1 Reply Last reply
      0
      • S Stuart Dootson

        To do this, I suspect you need to interface to Outlook using it's COM object model. I don't think ShellExecuteEx will cut it. This article[^] shows how to talk to Outlook using Javascript. C++ is more involved - to get anywhere, you probably want to be using #import with Outlook's type library - use #import "progid:Outlook.Application" auto_search to get VC++ to generate classes for the Outlook object model. Alternatively, this article[^] tells you how to do Office Automation with COM without using #import.

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        S Offline
        S Offline
        SNI
        wrote on last edited by
        #3

        thanks for your reply. But I want to know the event by which I come to know whether file gets attached or not so i can move further for processing. Any kind of idea will be helpful.

        SNI

        S 2 Replies Last reply
        0
        • S SNI

          thanks for your reply. But I want to know the event by which I come to know whether file gets attached or not so i can move further for processing. Any kind of idea will be helpful.

          SNI

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          Yeah, it's a bit different than just launching outlook with a parameter when you use COM. Here's some VBA that will start Outlook, create and send an e-mail.

          Dim o As Object 'will be an Outlook.Application
          Dim msg As Object 'will be a MailItem
          
          Set o = CreateObject("Outlook.Application")
          Set msg = o.CreateItem(0)
          msg.Subject = "_this is my subject_"
          
          msg.attachments.Add "_path to the attachment_"
          
          msg.body = "my message"
          
          msg.Recipients.Add "_an e-mail address_"
          
          msg.send
          

          You can replicate that relatively easily using the #import approach to interfacing with Outlook.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          1 Reply Last reply
          0
          • S SNI

            thanks for your reply. But I want to know the event by which I come to know whether file gets attached or not so i can move further for processing. Any kind of idea will be helpful.

            SNI

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #5

            C++ code for the VBA I posted - note that it's pretty much a direct translation...

            #import "progid:Outlook.Application" auto_search

            int main(int, char**)
            {
            try
            {
            CoInitializeEx(0, COINIT_APARTMENTTHREADED);
            Outlook::_ApplicationPtr ol(__uuidof(Outlook::Application));
            Outlook::_MailItemPtr msg(ol->CreateItem(Outlook::olMailItem));

              msg->Subject = "_this is my subject_";
              
              msg->Attachments->Add("_path to the attachment_");
            
              // If execution gets here, the attachment's been added to msg, and you can go on and do other stuff!
              
              msg->Body = "_my message_";
              
              msg->Recipients->Add("_an e-mail address_");
              
              msg->Send();
            

            }
            catch (_com_error& e)
            {
            std::cerr << (char*)e.Description() << std::endl;
            }
            return 0;
            }

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups