Solved

Using Outlook object in VB .Net

Posted on 2004-10-15
7
188 Views
Last Modified: 2010-04-23
I am attempting to use the outlook object in VB .Net to send an email.  In the code I declare my mailItem set it up but when I issue the command mailItem.send() it comes up with an error telling me that

   'send' is ambiguous across the inherited interfaces 'Outlook._MailItem' and 'Outlook.ItemEvents_Event'

I don't understand why this doesn't work I was working with sample code from msdn.  My other problem is that if I try to run the code anyway I get null references whenever I use the MailItem object.  But if I try to instantiate a new instance of the object I get an error saying that the _new()  method is private and cannot be access.  I am really not getting this.  
0
Comment
Question by:Seiera
  • 3
7 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
this should work (ofcourse you need to reference the outlook object library, Add reference/com/microsoft outlook ...)

Dim olApp As Outlook.Application
        Dim olMail As Outlook.MailItem
        olApp = New Outlook.Application

        olMail = olApp.CreateItem(Outlook.OlItemType.olMailItem)
        olMail.Recipients.Add("bla.bla@bla.com")
        olMail.Subject = "Your subject"
        olMail.HTMLBody = "Your HTML text"
        olMail.Attachments.Add("c:\ttt.txt", Outlook.OlAttachmentType.olByValue)
        olMail.Send()

0
 
LVL 1

Author Comment

by:Seiera
Comment Utility
Unfortunately not, I have added the reference and that is almost precisely the same code I had.  I copy and pasted it to see if I missed something but I still get both those errors.
0
 
LVL 1

Author Comment

by:Seiera
Comment Utility
I have ended up finding the solution to my problem.  The problem is actually a bug in the .Net environment.  The Outlook object has two Send classes, on related tot he _MailItem class and another to the _ItemEvents.Event class.  To solve the problem I would (using the above piece of code) have replaced olMail.send() with

CType(olMail, Outlook._MailItem).Send()

This ensures that there is no ambiguity and the code works.  I will be posting a message in community support requesting the points back.
0
 
LVL 1

Author Comment

by:Seiera
Comment Utility
Lunchy,

I thought I had made responses, or is that just the generic message you leave.
0
 

Accepted Solution

by:
RomMod earned 0 total points
Comment Utility
The question has been PAQ'd and the 125 points have been refunded.
RomMod
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now