User559576690 posted
Hi guys i this is jitender, i m having the solution of reading mails from outlook 2003,hope it will help to needy person,
you have to use Outlook Object Model for that.
add in the reference,
microsoft Outlook 11.0 object library.
than u have to referenced outlook redemption this dll will help us to hide security message.
code below
Public
Function PollEmailThroughOutlook()
As Boolean
Dim FilePath
As String
Dim PollMail
As String
Dim objFS As FileStream
Dim objSW As StreamWriter
Dim oInbox
As Outlook.Folders
Dim oTempFolder
As Outlook.MAPIFolder
Dim oFolders
As Outlook.Folders
Dim count As
Integer
FilePath = ConfigurationSettings.AppSettings(
"FilePath")
PollMail = ConfigurationSettings.AppSettings(
"PollMails")
Try
oApplication = CreateObject(
"Outlook.Application")
oNameSpace = oApplication.GetNamespace(
"MAPI")
oSafeItem = CreateObject(
"Redemption.SafeMailItem")
inbox = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
Try
SavedMailsAttachment = inbox.Parent
oTempFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
oFolders = oTempFolder.Folders
SavedMailsAttachment = oFolders.Add(PollMail, Outlook.OlDefaultFolders.olFolderInbox)
Catch ex As Exception
End Try
oInbox = inbox.Folders
SubFolder = inbox.Folders(
"PollMails")
count = inbox.Items.Count
Dim objMail
As Outlook.MailItem
Dim i As
Integer
If (inbox.Items.Count > 0)
Then
For i = 0 To count
objMail = oApplication.CreateItem(Outlook.OlItemType.olMailItem)
Try
objMail = inbox.Items(i + 1)
Catch ex As Exception
End Try
Dim obj As
Object
Dim AttachmentFile
As String
Dim OFileName
As String
Dim FileName
As String
Dim TextFilePath
As String
Dim sBody As
String
Dim objTxtFile
As FileInfo
For Each attachObject
As Outlook.Attachment
In objMail.Attachments
obj = attachObject.MAPIOBJECT
AttachmentFile = FilePath & attachObject.FileName
Dim objAFile
As FileInfo
objAFile =
New FileInfo(AttachmentFile)
If (objAFile.Exists)
Then
objAFile.Delete()
End If
attachObject.SaveAsFile(AttachmentFile)
FileName = attachObject.FileName.ToString()
OFileName = ExtFileNameFrmExt(FileName)
TextFilePath = FilePath & OFileName &
".txt"
objTxtFile =
New FileInfo(TextFilePath)
If (objTxtFile.Exists)
Then
objTxtFile.Delete()
End If
objFS =
New FileStream(TextFilePath, FileMode.CreateNew, FileAccess.Write)
objSW =
New StreamWriter(objFS)
oSafeItem.Item = objMail
sBody = oSafeItem.Body
objSW.Write(sBody)
objSW.Close()
objFS.Close()
objMail.Move(SubFolder)
i = i - 1
Next attachObject
Next
End If
Catch ex As Exception
End Try
End Function
One more thing i need to told you,we can't do this in C#.
Thanks
Jitender.
Software Developer
India.