CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #4
    Join Date
    May 2002
    Posts
    1,798

    Re: How to send attachment with MS Outlook automation?

    Thanks OReubens. I came across the same post somewhere. But it's an old post that doesnt appear to work using Win 7, Microsoft Outlook 12.0 Object Library <9.3> where I have added the classes from the Class Wizard:

    CApplication
    CAppointmentItem
    CContactItem
    CMailItem
    CMainSpace

    But trying to instantiate the object Attachments
    Code:
    Attachments atts( myMailItemObject.GetAttachments() ;
    is accompanied by the message:
    Error: object of abstract class type "Attachments" is not allowed
    I suspect that M$ made some changes in the OutLook automation classes and interfaces, e.g., myMailItemObject.GetAttachments() is now myMailItemObject.get_Attachements(). Further, there exist interfaces in the type library for Attachments which might be useful but I would prefer that someone who has used them might share their code rather than my endless fooling around with it.

    This post addresses the problem more directly, particularly with respect to earlier vs later versions of Visual Studio.

    http://social.msdn.microsoft.com/For...8-6205326f065d

    However, some here have expressed the opinion that social.msdn.microsoft.com/Forums are worth what you pay for them. : )

    OK. I added Attachment and Attachments from the Class Wizard type library and now I can instantiate a CAttachments object. But how to add file objects to this - given that I have a CString full pathname for the file?

    Code:
    LPDISPATCH atts.Add(VARIANT &Source, VARIANT &Type, VARIANT &Postion, VARIANT &DisplayName);
    I have tried this but clearly lack understanding of COM where m_vcsAttachments is a std::vector<CString> pathname:
    Code:
    	CAttachments atts;
    	COleVariant covOption((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
    
                  // Using the CComVariant: Smart Wrapper Class for VARIANT
    	CComVariant varSmartVariantString (m_vcsAttachments[0]);
    
    	//LPDISPATCH atts.Add(VARIANT &Source, VARIANT &Type, VARIANT &Postion, VARIANT &DisplayName);
    
    	atts.Add(varSmartVariantString,
    	covOption,
    	covOption,
    	covOption);
    
    	olMailItem.get_Attachments();
    
    	// Send the message
    	olMailItem.Send();
    Thanks to Siddartha: http://forums.codeguru.com/showthrea...ing-to-CString

    And now it compiles and runs and sends valid emails - BUT NO ATTACHMENTS ARE RECEIVED WITH THE EMAIL!

    I must be missing something.
    Still would appreciate your help on this.
    Last edited by Mike Pliam; January 11th, 2013 at 07:32 PM.
    mpliam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured