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 place the new mail in outbox of outlook programatically

How to place the new mail in outbox of outlook programatically

Scheduled Pinned Locked Moved C / C++ / MFC
testingtoolstutorial
4 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.
  • R Offline
    R Offline
    Rajesh match
    wrote on last edited by
    #1

    I need to place the mail in outbox i tried with automation and also with mapi apis,but no success anone have idea regarding this one Thanx

    D 1 Reply Last reply
    0
    • R Rajesh match

      I need to place the mail in outbox i tried with automation and also with mapi apis,but no success anone have idea regarding this one Thanx

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Show us the relevant code that is not working, and maybe we can offer suggestions.


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      R 1 Reply Last reply
      0
      • D David Crow

        Show us the relevant code that is not working, and maybe we can offer suggestions.


        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

        R Offline
        R Offline
        Rajesh match
        wrote on last edited by
        #3

        hello david this is my code for saving mail in outbox this is automation code its notworking but when i make call to send it send mail directly but i only need to place in outbox folder _Application pApp; COleException e; if(!pApp.CreateDispatch("Outlook.Application", &e)) { CString str; str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc); AfxMessageBox(str, MB_SETFOREGROUND); return; } COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); _NameSpace pNameSpace; MAPIFolder pOutbox; _Items pOutboxItems; Attachments pAttachments; Recipients pRecipients; Recipient pRecipient; // Create NameSpace pointer. pNameSpace = pApp.GetNamespace("MAPI"); pNameSpace.Logon(covOptional, covOptional, covOptional, covOptional); // Prepare a new mail message _MailItem pNewMail(pApp.CreateItem(0)); pOutbox = pNameSpace.GetDefaultFolder(4);//getoutbox folder pOutboxItems = pOutbox.GetItems(); pNewMail=pOutboxItems.Add(covOptional);//put the message in out boxx pNewMail.SetTo("global_com2000@yahoo.com"); pNewMail.SetSubject("Test..."); pNewMail.SetBody("Hi Mapi\n\n"); pRecipients.Add("global_com2000@yahoo.com"); // Resolve the recipient address. pRecipients .ResolveAll(); pNameSpace.Logoff();

        D 1 Reply Last reply
        0
        • R Rajesh match

          hello david this is my code for saving mail in outbox this is automation code its notworking but when i make call to send it send mail directly but i only need to place in outbox folder _Application pApp; COleException e; if(!pApp.CreateDispatch("Outlook.Application", &e)) { CString str; str.Format("CreateDispatch() failed w/error 0x%08lx", e.m_sc); AfxMessageBox(str, MB_SETFOREGROUND); return; } COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); _NameSpace pNameSpace; MAPIFolder pOutbox; _Items pOutboxItems; Attachments pAttachments; Recipients pRecipients; Recipient pRecipient; // Create NameSpace pointer. pNameSpace = pApp.GetNamespace("MAPI"); pNameSpace.Logon(covOptional, covOptional, covOptional, covOptional); // Prepare a new mail message _MailItem pNewMail(pApp.CreateItem(0)); pOutbox = pNameSpace.GetDefaultFolder(4);//getoutbox folder pOutboxItems = pOutbox.GetItems(); pNewMail=pOutboxItems.Add(covOptional);//put the message in out boxx pNewMail.SetTo("global_com2000@yahoo.com"); pNewMail.SetSubject("Test..."); pNewMail.SetBody("Hi Mapi\n\n"); pRecipients.Add("global_com2000@yahoo.com"); // Resolve the recipient address. pRecipients .ResolveAll(); pNameSpace.Logoff();

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Try this:

          _Application app;
          _NameSpace ns;
          MAPIFolder folderOutbox;
          _Items itemsMessages;
          _MailItem mi;
          long olFolderOutbox((long) 4);
          COleVariant vtOptional((long) DISP_E_PARAMNOTFOUND, VT_ERROR),
          vtTrue((short) TRUE);

          if (app.CreateDispatch("Outlook.Application") == TRUE)
          {
          ns = app.GetNamespace("MAPI");

          ns.Logon(vtOptional, vtOptional, vtTrue, vtTrue);
              
          folderOutbox = ns.GetDefaultFolder(olFolderOutbox);
          
          itemsMessages = folderOutbox.GetItems();
          
          mi = itemsMessages.Add(vtOptional);
          
          mi.SetTo("global\_com2000@yahoo.com");
          mi.SetSubject("Test...");
          mi.SetBody("Hi Mapi\\n\\n");
              
          mi.Send();
          
          ns.Logoff();
          

          }


          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

          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