Solved

Using Outlook to send email within Visual Basic .NET

Posted on 2007-03-26
16
229 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
  • 9
  • 6
16 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
Comment Utility
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
Comment Utility
and also use imports statement
Imports Microsoft.Office.Interop.Outlook.
0
 
LVL 1

Author Comment

by:bri_stc
Comment Utility
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
 
LVL 21

Expert Comment

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

Author Comment

by:bri_stc
Comment Utility
I have done that already but no give~
0
 
LVL 21

Expert Comment

by:theGhost_k8
Comment Utility
0
 
LVL 21

Expert Comment

by:theGhost_k8
Comment Utility
also www.outlookcode.com for some good tutorials
0
 
LVL 1

Author Comment

by:bri_stc
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 21

Expert Comment

by:theGhost_k8
Comment Utility
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
Comment Utility
oops i am sorry my mistake...
0
 
LVL 21

Expert Comment

by:theGhost_k8
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I have finally found the answer!!!   olmailitem is listed under Outlook.OlItemType.olMailItem

Thanks theGhost_k8...  handing you the point now!
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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

728 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