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

Threaded View

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

    Re: How to send attachment with MS Outlook automation?

    Found a method that works. Turns out you do need both Attachment and Attachments interfaces from the Class Wizard type library.
    The following code adopted from this site works to send an email with an attachment.
    see: http://us.generation-nt.com/answer/s...-49590791.html
    Code:
    	CAttachments atts;
    
    	 //COleVariant oAttachLocation(oStr);
    	 COleVariant oAttachLocation(m_vcsAttachments[0]);
    	 COleVariant covOption((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
    	 CAttachments olAths = olMailItem.get_Attachments();
     	 CAttachment olNewAth = olAths.Add(oAttachLocation,
    	 covOption,
    	 covOption,
    	 covOption);
    
    	// Send the message
    	olMailItem.Send();
    I'll need to do some extensive testing to see which types of files are acceptable and how many attachments including images, pdf, txt, etc will go through. I've posted this painful step by step in the hope that it will help some others.

    BTW Igor, I use the Microsoft Outlook type library as a wrapper for all that COM code which frankly makes me a bit dizzy whenever I see it. But thanks for your input which I always appreciate. : )
    Last edited by Mike Pliam; January 11th, 2013 at 08:01 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