locked
Read Mails from Outlook 2003 Programmaticaly Without Security Message Shown. RRS feed

  • Question

  • 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.

    Tuesday, April 17, 2007 2:56 AM

All replies

  • User-464213005 posted

    Hi,

     I have created a web application in c# and executed it. in the debug mode that is when i am executing the application in my machine i am able to read the mails, but when i created virtual directory and accessing it from my own computer/system using the IP instead of locahost its asking for credentials, even if i give my own windows autentication credentials it says not authorized to view the page. I am unable to access it from other systems too..

     Will your code can be used to access the outlook mails if we create the virtual directory and access. If so pls let me know.

     Regards,

    Madhan

    Tuesday, December 4, 2007 8:37 AM
  • User-177039463 posted

    When I try to add a reference in VS 2005, I cannot find that library in either .net or com objects.  anyone have any ideas of where I can get this or find it? 

    Monday, December 31, 2007 1:11 PM