![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
Hi,
I am looking for some help here. I am trying to read email from an inbox. The emails are bouncebacks. I want to be able to parse the message body to get email addesses etc. Problem is it hangs on the first line -- oMsg = CType(oItems.Item(i), Outlook.MailItem) after it goes through one loop Below is the code I am using. Option Strict On Imports System.ServiceProcess Imports MAPI Imports Outlook = Microsoft.Office.Interop.Outlook Imports System.Runtime.InteropServices.Marshal Imports System.Reflection Imports Redemption Dim BodyStr As String Dim oApp As Outlook.Application = New Outlook.Application Dim i As Integer ' Get Mapi NameSpace. Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi") oNS.Logon("outlook_profile", "password", False) ' Get Messages collection of Inbox. Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFo lderInbox) Dim oItems As Outlook.Items = oInbox.Items ' Loop each unread message. Dim oMsg As Outlook.MailItem Dim oSafeMsg As Redemption.SafeMailItem For i = 1 To oItems.Count oMsg = CType(oItems.Item(i), Outlook.MailItem) ' hangs on this line after the first loop oSafeMsg = New Redemption.SafeMailItem oSafeMsg.Item = oMsg BodyStr = oSafeMsg.Body ' parse code goes here ReleaseComObject(oMsg) oMsg = Nothing Next ' Log off. oNS.Logoff() ' Clean up. ReleaseComObject(oApp) oApp = Nothing ReleaseComObject(oNS) oNS = Nothing ReleaseComObject(oItems) oItems = Nothing GC.Collect() GC.WaitForPendingFinalizers() End Sub Any ideas ? Any help would be appreciated Thanks Damian |
#2
|
|||
|
|||
![]()
Are you sure the item or items in question are MailItem objects?
Using Redemption I'd probably use RDOMail objects and RDOFolder to get the Inbox from the RDOSession object, that way I'd avoid problems like that. Then I could check the Class or MessageClass of the RDOMail object before working with it. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Damian" wrote in message oups.com... Hi, I am looking for some help here. I am trying to read email from an inbox. The emails are bouncebacks. I want to be able to parse the message body to get email addesses etc. Problem is it hangs on the first line -- oMsg = CType(oItems.Item(i), Outlook.MailItem) after it goes through one loop Below is the code I am using. Option Strict On Imports System.ServiceProcess Imports MAPI Imports Outlook = Microsoft.Office.Interop.Outlook Imports System.Runtime.InteropServices.Marshal Imports System.Reflection Imports Redemption Dim BodyStr As String Dim oApp As Outlook.Application = New Outlook.Application Dim i As Integer ' Get Mapi NameSpace. Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi") oNS.Logon("outlook_profile", "password", False) ' Get Messages collection of Inbox. Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFo lderInbox) Dim oItems As Outlook.Items = oInbox.Items ' Loop each unread message. Dim oMsg As Outlook.MailItem Dim oSafeMsg As Redemption.SafeMailItem For i = 1 To oItems.Count oMsg = CType(oItems.Item(i), Outlook.MailItem) ' hangs on this line after the first loop oSafeMsg = New Redemption.SafeMailItem oSafeMsg.Item = oMsg BodyStr = oSafeMsg.Body ' parse code goes here ReleaseComObject(oMsg) oMsg = Nothing Next ' Log off. oNS.Logoff() ' Clean up. ReleaseComObject(oApp) oApp = Nothing ReleaseComObject(oNS) oNS = Nothing ReleaseComObject(oItems) oItems = Nothing GC.Collect() GC.WaitForPendingFinalizers() End Sub Any ideas ? Any help would be appreciated Thanks Damian |
#3
|
|||
|
|||
![]()
Hi Ken,
Thanks for your response. I am sure they are MailItem objects as the first time it loops through I could see the body of the email. I need to be able to read the body of the email when it comes back from a bounce back. Apparently there is a difference in reading the body of an email from when someone sends an email to another person, compared to when the server returns an automated message from a bounceback. I dont have any experience in dealing with MAPI and messaging and I cant find a full example of what I need to do on the Redemption website. It seems to gives you bits and pieces but no full examples or am I missing something? Regards Damian Ken Slovak - [MVP - Outlook] wrote: Are you sure the item or items in question are MailItem objects? Using Redemption I'd probably use RDOMail objects and RDOFolder to get the Inbox from the RDOSession object, that way I'd avoid problems like that. Then I could check the Class or MessageClass of the RDOMail object before working with it. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Damian" wrote in message oups.com... Hi, I am looking for some help here. I am trying to read email from an inbox. The emails are bouncebacks. I want to be able to parse the message body to get email addesses etc. Problem is it hangs on the first line -- oMsg = CType(oItems.Item(i), Outlook.MailItem) after it goes through one loop Below is the code I am using. Option Strict On Imports System.ServiceProcess Imports MAPI Imports Outlook = Microsoft.Office.Interop.Outlook Imports System.Runtime.InteropServices.Marshal Imports System.Reflection Imports Redemption Dim BodyStr As String Dim oApp As Outlook.Application = New Outlook.Application Dim i As Integer ' Get Mapi NameSpace. Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi") oNS.Logon("outlook_profile", "password", False) ' Get Messages collection of Inbox. Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFo lderInbox) Dim oItems As Outlook.Items = oInbox.Items ' Loop each unread message. Dim oMsg As Outlook.MailItem Dim oSafeMsg As Redemption.SafeMailItem For i = 1 To oItems.Count oMsg = CType(oItems.Item(i), Outlook.MailItem) ' hangs on this line after the first loop oSafeMsg = New Redemption.SafeMailItem oSafeMsg.Item = oMsg BodyStr = oSafeMsg.Body ' parse code goes here ReleaseComObject(oMsg) oMsg = Nothing Next ' Log off. oNS.Logoff() ' Clean up. ReleaseComObject(oApp) oApp = Nothing ReleaseComObject(oNS) oNS = Nothing ReleaseComObject(oItems) oItems = Nothing GC.Collect() GC.WaitForPendingFinalizers() End Sub Any ideas ? Any help would be appreciated Thanks Damian |
#4
|
|||
|
|||
![]()
NDRs are represented by the ReportItem object in OOM, not MailItem. That's
the reason you get the error. To loop through the items in the Inbox folder, try something likee the following (VB) set Session = CreateObject("Redemption.RDOSession") Session.Logon set Inbox = Session.GetDefaultFolder(olFolderInbox) set Items = Inbox.Items for each Msg in Items Debug.Print Msg.Subject next Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Damian" wrote in message ps.com... Hi Ken, Thanks for your response. I am sure they are MailItem objects as the first time it loops through I could see the body of the email. I need to be able to read the body of the email when it comes back from a bounce back. Apparently there is a difference in reading the body of an email from when someone sends an email to another person, compared to when the server returns an automated message from a bounceback. I dont have any experience in dealing with MAPI and messaging and I cant find a full example of what I need to do on the Redemption website. It seems to gives you bits and pieces but no full examples or am I missing something? Regards Damian Ken Slovak - [MVP - Outlook] wrote: Are you sure the item or items in question are MailItem objects? Using Redemption I'd probably use RDOMail objects and RDOFolder to get the Inbox from the RDOSession object, that way I'd avoid problems like that. Then I could check the Class or MessageClass of the RDOMail object before working with it. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Damian" wrote in message oups.com... Hi, I am looking for some help here. I am trying to read email from an inbox. The emails are bouncebacks. I want to be able to parse the message body to get email addesses etc. Problem is it hangs on the first line -- oMsg = CType(oItems.Item(i), Outlook.MailItem) after it goes through one loop Below is the code I am using. Option Strict On Imports System.ServiceProcess Imports MAPI Imports Outlook = Microsoft.Office.Interop.Outlook Imports System.Runtime.InteropServices.Marshal Imports System.Reflection Imports Redemption Dim BodyStr As String Dim oApp As Outlook.Application = New Outlook.Application Dim i As Integer ' Get Mapi NameSpace. Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi") oNS.Logon("outlook_profile", "password", False) ' Get Messages collection of Inbox. Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFo lderInbox) Dim oItems As Outlook.Items = oInbox.Items ' Loop each unread message. Dim oMsg As Outlook.MailItem Dim oSafeMsg As Redemption.SafeMailItem For i = 1 To oItems.Count oMsg = CType(oItems.Item(i), Outlook.MailItem) ' hangs on this line after the first loop oSafeMsg = New Redemption.SafeMailItem oSafeMsg.Item = oMsg BodyStr = oSafeMsg.Body ' parse code goes here ReleaseComObject(oMsg) oMsg = Nothing Next ' Log off. oNS.Logoff() ' Clean up. ReleaseComObject(oApp) oApp = Nothing ReleaseComObject(oNS) oNS = Nothing ReleaseComObject(oItems) oItems = Nothing GC.Collect() GC.WaitForPendingFinalizers() End Sub Any ideas ? Any help would be appreciated Thanks Damian |
#5
|
|||
|
|||
![]()
Hi Dmitry,
Thanks for your reply. What are NDR's? I need to be able to read the body an email bounceback. I am able to read the body of a standard email, but I cant read the body of an email bounce back. It returns empty. Regards Damian Dmitry Streblechenko wrote: NDRs are represented by the ReportItem object in OOM, not MailItem. That's the reason you get the error. To loop through the items in the Inbox folder, try something likee the following (VB) set Session = CreateObject("Redemption.RDOSession") Session.Logon set Inbox = Session.GetDefaultFolder(olFolderInbox) set Items = Inbox.Items for each Msg in Items Debug.Print Msg.Subject next Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Damian" wrote in message ps.com... Hi Ken, Thanks for your response. I am sure they are MailItem objects as the first time it loops through I could see the body of the email. I need to be able to read the body of the email when it comes back from a bounce back. Apparently there is a difference in reading the body of an email from when someone sends an email to another person, compared to when the server returns an automated message from a bounceback. I dont have any experience in dealing with MAPI and messaging and I cant find a full example of what I need to do on the Redemption website. It seems to gives you bits and pieces but no full examples or am I missing something? Regards Damian Ken Slovak - [MVP - Outlook] wrote: Are you sure the item or items in question are MailItem objects? Using Redemption I'd probably use RDOMail objects and RDOFolder to get the Inbox from the RDOSession object, that way I'd avoid problems like that. Then I could check the Class or MessageClass of the RDOMail object before working with it. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Damian" wrote in message oups.com... Hi, I am looking for some help here. I am trying to read email from an inbox. The emails are bouncebacks. I want to be able to parse the message body to get email addesses etc. Problem is it hangs on the first line -- oMsg = CType(oItems.Item(i), Outlook.MailItem) after it goes through one loop Below is the code I am using. Option Strict On Imports System.ServiceProcess Imports MAPI Imports Outlook = Microsoft.Office.Interop.Outlook Imports System.Runtime.InteropServices.Marshal Imports System.Reflection Imports Redemption Dim BodyStr As String Dim oApp As Outlook.Application = New Outlook.Application Dim i As Integer ' Get Mapi NameSpace. Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi") oNS.Logon("outlook_profile", "password", False) ' Get Messages collection of Inbox. Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFo lderInbox) Dim oItems As Outlook.Items = oInbox.Items ' Loop each unread message. Dim oMsg As Outlook.MailItem Dim oSafeMsg As Redemption.SafeMailItem For i = 1 To oItems.Count oMsg = CType(oItems.Item(i), Outlook.MailItem) ' hangs on this line after the first loop oSafeMsg = New Redemption.SafeMailItem oSafeMsg.Item = oMsg BodyStr = oSafeMsg.Body ' parse code goes here ReleaseComObject(oMsg) oMsg = Nothing Next ' Log off. oNS.Logoff() ' Clean up. ReleaseComObject(oApp) oApp = Nothing ReleaseComObject(oNS) oNS = Nothing ReleaseComObject(oItems) oItems = Nothing GC.Collect() GC.WaitForPendingFinalizers() End Sub Any ideas ? Any help would be appreciated Thanks Damian |
#6
|
|||
|
|||
![]()
NDR's are non-delivery reports. As Dmitry said and I indicated those items
are not MailItems, they are ReportItems and that's why your code is failing. Use RDOMail instead of SafeMailItem, which is only for MailItem or use the Redemption.MessageItem object. -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Damian" wrote in message oups.com... Hi Dmitry, Thanks for your reply. What are NDR's? I need to be able to read the body an email bounceback. I am able to read the body of a standard email, but I cant read the body of an email bounce back. It returns empty. Regards Damian |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
envelopes and labels and useing a shared contact list | Glenn Reed | Outlook - Using Contacts | 0 | May 31st 06 05:48 PM |
outlook express and explorer go off line useing DSL | Ginepaul | Outlook Express | 2 | March 13th 06 03:00 PM |
Waht is the fastest/bets? Outlook Object/CDO/Redemption/...? | Pieter | Outlook and VBA | 2 | February 2nd 06 12:04 PM |
Undefined Object: testing for Nothing (Redemption) | Martin | Outlook and VBA | 3 | January 25th 06 10:21 AM |
Read Msgs Marked as Read? | ERoss | Outlook - General Queries | 0 | January 23rd 06 07:44 PM |