Solved

Using Outlook object in VB .Net

Posted on 2004-10-15
7
212 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
ID: 12318715
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
ID: 12321699
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
ID: 12351131
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
ID: 12353400
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
ID: 12389463
The question has been PAQ'd and the 125 points have been refunded.
RomMod
Community Support Moderator
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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