Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to read outlook emails using vb.net

Posted on 2014-09-26
9
Medium Priority
?
1,262 Views
Last Modified: 2014-09-30
Hi, I need to read the emails from outlook. The code is giving me an error

        Dim objOL As Outlook.Application
        Dim objNS As Outlook.NameSpace
        Dim objFolder As Outlook.Folders
        Dim Item As Object
        'Dim myItems As Outlook.Items
        Dim x As Int16

        objOL = New Outlook.Application()
        objNS = objOL.GetNamespace("MAPI")

        Dim olfolder As Outlook.MAPIFolder
        If direction = "IN" Then
            olfolder = objOL.GetNamespace("Mapi").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
        Else
            olfolder = objOL.GetNamespace("Mapi").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail)
        End If

        myItems = olfolder.Items

It bombs in the ofolder.items giving an error :

Interface not registered (Exception from HRESULT: 0x80040155)

I appreciate your help experts. Thanks
0
Comment
Question by:fmichail
[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
  • 5
  • 4
9 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40347551
I prefer not use automation to read Excel. I use http://www.limilabs.com/mail
0
 

Author Comment

by:fmichail
ID: 40347702
Eric Moreau,
Thanks for the response, however, I am restricted to interface the application with outlook. Can mail.dll interface with outlook? Like list emails from outlook / send email through outlook / open and view outlook / retrieve the outlook currently selected email?

In fact I have little understanding of how emails are retreived, and saved in general. however, the component looks encouraging  if it interfaces with outlook.

Please reply. Thanks
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 40347749
mail.dll is like connecting to your mail server to retrieve them, read, delete

if you would like to send email, you better just use the .Net framework system.net.mail (http://systemnetmail.com/)
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:fmichail
ID: 40348161
Thanks again Eric, the application is targeting a company which uses outlook for emails. Can mail.dll connect to where the emails of the users are (I do not know where outlook retrieves them from), and retrieve these emails even while outlook is working ... in other words, is there any setting (or coding) to tell mail.dll how retrieve the outlook emails for the current user... Sorry Eric, I do not know how outlook works... Please reply. when the mail.dll sends an email, will it show in the outlook sent folder... I hope you know what I mean.. Thanks in advance.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40348545
mail.dll will not do that. It has to be configured with the credentials of the user to connect to the Exchange server. Also, it won't put emails in the sent items.

You are probably better to stick with automation then!
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40348547
0
 

Author Comment

by:fmichail
ID: 40352790
Hi Eric,
Yes I tried the same code, but unfortunately, I got the same error in the same spot. by the way, is it the same to reference MS outlook object library (as in your like) OR to reference MS.Office.Interop.outlook?.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40352922
yes
0
 

Author Closing Comment

by:fmichail
ID: 40353410
Although my problem is not fixed, however, Eric directed to a better way of handling Emails, that I will definitely consider. Thanks Eric
0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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