Solved

Using Outlook to send email within Visual Basic .NET

Posted on 2007-03-26
16
234 Views
Last Modified: 2010-04-23
Hello,

I am trying to send email by Outlook using Visual Basic. Microsoft has a article on it: http://support.microsoft.com/kb/220595

For some reason, Dim olApp As Outlook.Application ....   where Outlook.Application is not found by VB .NET...

What can I do to fix this? Is there a class that I need to Imports in order to work?

Thanks
0
Comment
Question by:bri_stc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
16 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 18796604
Hi bri_stc,

You will need to add a reference to Outlook as instructed in the article.

Regards,

Wayne
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18797836
and also use imports statement
Imports Microsoft.Office.Interop.Outlook.
0
 
LVL 1

Author Comment

by:bri_stc
ID: 18801810
Hello experts,

Adding the references have solve majority of the problem.

Now I am only down to these not being recognize:

olItem = olApp.CreateItem(olContactItem)  <------- where olContactItem is not recognize
olAppt = olApp.CreateItem(olAppointmentItem)<------- where olAppointmentItem is not recognize
olMail = olApp.CreateItem(olMailItem) <------- where olMailItem is not recognize

:) I am fairly green in VB .NET
Thanks

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18801870
Dim olAppt As Outlook.AppointmentItem
and same is the others
0
 
LVL 1

Author Comment

by:bri_stc
ID: 18801909
I have done that already but no give~
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18801910
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18801924
also www.outlookcode.com for some good tutorials
0
 
LVL 1

Author Comment

by:bri_stc
ID: 18801995
I think i have done that already...

In fact, i just want to be able to sent email out and this is what i have:

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        ' Start Outlook.
        ' If it is already running, you'll use the same instance...
        Dim olApp As Outlook.Application
        olApp = CreateObject("Outlook.Application")

        ' Logon. Doesn't hurt if you are already running and logged on...
        Dim olNs As Outlook.NameSpace
        olNs = olApp.GetNamespace("MAPI")
        olNs.Logon()



        ' Send a message to your new contact.
        Dim olMail As Outlook.MailItem
        olMail = olApp.CreateItem(olMailItem)
        ' Fill out & send message...
        olMail.To = "test@test.com"
        olMail.Subject = "About our meeting..."
        olMail.Body = _
             "Dear " & "Whomever is concern" & ", " & vbCr & vbCr & vbTab & _
             "I'll see you in 2 minutes for our meeting!" & vbCr & vbCr & _
             "Btw: I've added you to my contact list."
        olMail.Send()

        ' Clean up...
        MsgBox("All done...", vbMsgBoxSetForeground)
        olNs.Logoff()
        olNs = Nothing
        olMail = Nothing

        olApp = Nothing

    End Sub

___________________________

I am getting a error there:   olMail = olApp.CreateItem(olMailItem)  <----- olMailitem is undefine....
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18802464
Dim olMail As Outlook.MailItem << I site prob here
olMail = olApp.CreateItem(olMailItem)

Dim olMailItem As Outlook.MailItem << it should be like this
olMail = olApp.CreateItem(olMailItem)
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18802500
oops i am sorry my mistake...
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18802533
Imports Microsoft.Office.Interop.Outlook
olMailItem should be there in Outlook's properties
Outlook.olMailItem or Outlook.items.olMailitem
0
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18802598
you add a reference to Outlook object Library from Project -> References correct?  
Now if you go to View -> Object Browser, select the Outlook Library from the dropdown list to get all methods, etc.


you try this in a saperate app and check if the flow is correct.. this error points me to missing ref.
0
 
LVL 21

Accepted Solution

by:
theGhost_k8 earned 250 total points
ID: 18802654
try this too..

CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
you might need to typecast Outlook.MailItem

please check  the references
0
 
LVL 1

Author Comment

by:bri_stc
ID: 18802818
I am looking at the object browser right now, I dont see olMailItem in the reference list...

and for some reason, Microsoft.Office.Interop.Outlook dont seem to exist....

here is a screen shot of the object browser:
http://img107.imageshack.us/my.php?image=referencespv9.jpg
0
 
LVL 1

Author Comment

by:bri_stc
ID: 18802898
How about this:
 
Dim sendingemail As Outlook.MailItem

sendingemail.To = "mmok@stcbus.com"
sendingemail.Subject = "About our meeting..."
sendingemail.Body = _
             "Dear " & "Whomever is concern" & ", " & vbCr & vbCr & vbTab & _
             "I'll see you in 2 minutes for our meeting!" & vbCr & vbCr & _
             "Btw: I've added you to my contact list."
sendingemail.Send()

Just to make things simply, but now I am getting a error with this line when I run it: sendingemail.To = "mmok@stcbus.com"....  but it compile just fine, just when I execute the send, this line causes an error.
0
 
LVL 1

Author Comment

by:bri_stc
ID: 18802953
I have finally found the answer!!!   olmailitem is listed under Outlook.OlItemType.olMailItem

Thanks theGhost_k8...  handing you the point now!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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