2

I have been using R's RDCOMClient package to manipulate Excel files and it has been a tremendous help.

Now I am venturing on to using Outlook and have learned how to send mail using the thread here

However, I want to use R's RDCOMClient to retrieve messages from my inbox.

In general, we can convert VBA code for use with RDCOMClient, though I am having trouble in certain cases with proper syntax.

i.e. when to access a member of an object using Object[["example"]] or Object$example(); and how to make something like Object$example(test$()) work.

More specifically, how would I convert the following code from MSDN on retrieving mail using VBA?

    Dim outlookNameSpace As Outlook.NameSpace
Dim inbox As Outlook.MAPIFolder
Dim WithEvents items As Outlook.Items

Private Sub ThisAddIn_Startup() Handles Me.Startup

    outlookNameSpace = Me.Application.GetNamespace("MAPI")
    inbox = _
        outlookNameSpace.GetDefaultFolder( _
        Outlook.OlDefaultFolders.olFolderInbox)
    items = inbox.Items

End Sub 

Private Sub Items_ItemAdd(ByVal item As Object) Handles items.ItemAdd
    Dim filter As String = "USED CARS" 
    If TypeOf (item) Is Outlook.MailItem Then 
        Dim mail As Outlook.MailItem = item
        If mail.MessageClass = "IPM.Note" And _
 mail.Subject.ToUpper.Contains(filter.ToUpper) Then
            mail.Move(outlookNameSpace.GetDefaultFolder( _
                Outlook.OlDefaultFolders.olFolderJunk))
        End If 
    End If 

End Sub

Here I made some attempts in R like:

OL = COMCreate("Outlook.Application")
outlookNameSpace = OL$GetNameSpace("MAPI")

with ideas of following the logic presented in the VBA code. However, I run into the problems mentioned above where the syntax for accessing members and methods is not easily translated.

    subpath = OL$OlDefaultFolders()$olFolderInbox()
##Or something like
    subpath = OL$DefaultFolders()
    subpath2 = subpath$olFolderInbox()

Ultimately, my question (and one potentially posed by others) can be best by a direct conversion of the MSDN example from VBA to R, or a link to a comprehensive tutorial.

And for the record I have already read this great tutorial on RDCOMClient

I appreciate any help you can give me, and I think this topic would be a great launchpad for general VBA -> RDCOM ideas

rkingsley
  • 21
  • 2
  • You might check out my answer to this question: http://stackoverflow.com/questions/42573699/how-to-retrieve-outlook-inbox-emails-using-r-rdcomclient/42590894#42590894 Are you really trying to capture incoming email events (as shown in the VBA sample), or do you just want to walk the list of inbox emails? – Greg Thatcher Mar 08 '17 at 19:58
  • Has anyone tried this out yet for reading attachments in r with an image in the body of an email? https://stackoverflow.com/questions/48695427/extracting-zipcsv-file-from-attachment-w-image-in-body-of-email – nak5120 Feb 09 '18 at 14:13

0 Answers0