Assistance needed in downloading emails directly from exchange server (1 Viewer)

Voyager

Registered User.
Local time
Today, 11:45
Joined
Sep 7, 2017
Messages
95
Hi team,
I am downloading emails from outlook to ms access using below given codes. Timer function will activate these codes and download mails. But i heard there is a way to directly download the mails from exchange server instead of relying on outlook. Since database will be more stable if data is directly getting downloaded from server rather than relying on timer function. I tried for several days still I coul not find a solution. Could you assist me in modifying below given code so that I can download mails directly from server.

Code:
Private Sub getml()
Dim rst As DAO.Recordset
Dim OlApp As Outlook.Application

Dim inbox As Outlook.MAPIFolder
Dim inboxItems As Outlook.Items
Dim Mailobject As Object
Dim db As DAO.Database
Dim dealer As Integer
Set db = CurrentDb

Set OlApp = CreateObject("Outlook.Application")
Set inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFold erInbox)
Set rst= CurrentDb.OpenRecordset("mls")
Set inboxItems = inbox.Items
For Each Mailobject In inboxItems

With rst
.AddNew
!task= Mailobject.UserProperties.Find("taskID")
!estml= Mailobject.UserProperties.Find("estimate")
.Update

Mailobject.UnRead = False
End With
End If
Next
Set OlApp = Nothing
Set inbox = Nothing
Set inboxItems = Nothing
Set Mailobject = Nothing
End Sub

Code:
Private Sub sntml()
Dim rst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim stfldr As Outlook.MAPIFolder
Dim stfldrItems As Outlook.Items
Dim Mailobject As Object
Dim db As DAO.Database
Dim dealer As Integer
Dim emailCount as integer

Set db = CurrentDb
Set OlApp = CreateObject("Outlook.Application")
Set stfldr = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderSentMail)
Set rst= CurrentDb.OpenRecordset("ogmls")
Set stfldrItems = stfldr.Items
stfldrItems.Sort "[ReceivedTime]"
emailCount=1
For Each Mailobject In stfldrItems

    With rst
        .AddNew
        !Subject = Mailobject.Subject
        !from = Mailobject.SenderName
        !To = Mailobject.To
        !Body = Mailobject.Body
        !DateSent = Mailobject.SentOn
        .Update
        Mailobject.UnRead = False
    End With
    emailCount = emailCount+1
    if emailCount > 10 then 
      Exit For
    end if

Next
Set OlApp = Nothing
Set stfldr = Nothing
Set stfldrItems = Nothing
Set Mailobject = Nothing
Set rst = Nothing
End Sub
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 02:15
Joined
Apr 27, 2015
Messages
6,317
You can link the outlook folders directly as tables and then make forms, reports, anything you could do with ya le data.

Choose “more” from the Import / External Data option on the Ribbon (depending on what version of Access you are using), then Outlook and follow the prompts.
 

Voyager

Registered User.
Local time
Today, 11:45
Joined
Sep 7, 2017
Messages
95
Hi Nauticalgent,
Thanks for the suggestion. However I forgot to update one thing, the mails which are coming to these folders are form mails so default option is not downloading form fields hence that method is not working I have already attempted and failed.
 

Voyager

Registered User.
Local time
Today, 11:45
Joined
Sep 7, 2017
Messages
95
Hi team,
Could you assist me in this issue. Or could you guide where to look for answers to this?
 

Users who are viewing this thread

Top Bottom