Click here to Skip to main content
Licence 
First Posted 15 Mar 2006
Views 47,351
Bookmarked 32 times

Extracting mails and attachments from outlook 2003 in vb.net

By | 15 Mar 2006 | Article
Extracting mails

Introduction

hi,

Here, I am putting some sample code for extractng mails and attachments from Outlook 2003 using VB.NET.

The program will extarct the mail from selected folder in Outlook 2003.

For this, first add a reference to Outlook.

****write this code for getting the mails ***************

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
olfolder = objOL.GetNamespace("MAPI").PickFolder
myItems = olfolder.Items

Dim i As Integer
For x = 1 To myItems.Count
    messagebox.show(myItems.Item(x).SenderName) 
    messagebox.show myItems.Item(x).SenderEmailAddress)
    messagebox.showmyItems.Item(x).Subject)
    messagebox.showmyItems.Item(x).Body)
    messagebox.show myItems.Item(x).to)
    messagebox.showmyItems.Item(x).ReceivedByName)
    messagebox.show myItems.Item(x).ReceivedOnBehalfOfName)
    messagebox.showmyItems.Item(x).ReplyRecipientNames)
    messagebox.showmyItems.Item(x).SentOnBehalfOfName)
    messagebox.showmyItems.Item(x).CC)
    messagebox.show myItems.Item(x).ReceivedTime)
Next x

***********for getting attachments use this code******************

Dim Atmt As Outlook.Attachment

For Each Atmt In Item.Attachments
    filename = "C:\Email Attachments\" + Atmt.FileName
    Atmt.SaveAsFile(filename)
Next Atmt

Try it out .. and let me know if there is any problem.

Thanks.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

shihasnaas

Web Developer

India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalhi I am facing a problem with the code you have displayed can u please help me PinmemberMember 78419496:24 14 Apr '11  
GeneralRe: hi I am facing a problem with the code you have displayed can u please help me PinmemberMember 78419496:58 14 Apr '11  
GeneralMy vote of 1 PinmvpDave Kreskowiak8:28 23 Dec '09  
Generalreading attachments with different file extensions Pinmemberbhavna81620:10 19 Mar '07  
QuestionHow can I test about "Extracting mails and attachments from outlook 2003 in vb.net " Pinmemberhoplq0:57 27 Sep '06  
GeneralEmbedded email PinmemberBobSnowden6:02 19 Sep '06  
QuestionHow to compare your approach with Simple MAPI as in this article? Pinmembertank20912:36 6 Apr '06  
Questionhow to import a mail PinmemberChris_kun17:51 28 Mar '06  
AnswerRe: how to import a mail Pinmembertank20912:38 6 Apr '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 16 Mar 2006
Article Copyright 2006 by shihasnaas
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid