PDA

View Full Version : How to copy the subject and body from IMAP mails?



KHPoulsen
01-18-2016, 07:53 AM
Hi guys,

I have a problem regarding IMAP4 and Outlook.

I have no problem reading and copying the body and the subject of mails from my Exhange account in Outlook.

However, I also have an IMAP4/SMTP email account (created via the website hosting service I'm using) in Outlook, for which I also want to extract the body and subject for every unread mail.

I tried to use the same VBA code which I made to extract the data from my Exchange mails, but I dosen't work.

I'm using the following code for the Exchange account, and it works just great:

Dim objInbox As Object
Dim objOutlook As Object
Dim objnSpace As Object
Dim objMessage As Object
Dim objSubfolder As Object


Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")
Set objInbox = objnSpace.GetDefaultFolder(olFolderInbox)
Set objSubfolder = objInbox.Folders.Item("Orders")

For Each objMessage In objSubfolder.Items
If objMessage.unread = True Then
Worksheets("Data").Range("A2") = objSubfolder.Items(i).Body
End if
Next objMessage


Can you guys help me to extract the SAME information (body) from the IMAP4 account rather than the Exchange account?

In advance, thanks!

Regards,

Kristoffer