|
-
Jul 16th, 2007, 04:22 AM
#1
Thread Starter
Hyperactive Member
-
Jul 16th, 2007, 08:10 AM
#2
Re: Mail Retriever for Microsoft Outlook Exchange
VB6's MAPI controls were released back in 1998 so they might not be fully compatible with MS Office Outlook. I suggest you use Outlook's object model instead.
-
Jul 16th, 2007, 09:40 AM
#3
Thread Starter
Hyperactive Member
Re: Mail Retriever for Microsoft Outlook Exchange
 Originally Posted by RhinoBull
VB6's MAPI controls were released back in 1998 so they might not be fully compatible with MS Office Outlook. I suggest you use Outlook's object model instead.
ok cool Rhino,
have managed (i think), with Outlook Object Model..
so far, code accesses local inbox fine...
trying to use the Outlook-Table Object, to filter down to only desired e-mails,(in this case UnRead/New e-mails).
but falling over the filter parameter.. (codeLine=9):
vb Code:
Dim objOutlook As Interop.Outlook.Application
'Dim objMessage As Interop.Outlook.MailItem
objOutlook = New Interop.Outlook.Application
'objMessage = objOutlook.CreateItem(Interop.Outlook.OlItemType.olMailItem)
Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace
oNS = objOutlook.GetNamespace("mapi")
Dim oFolder As Interop.Outlook.MAPIFolder
oFolder = oNS.GetDefaultFolder(Interop.Outlook.OlDefaultFolders.olFolderInbox)
Dim filter As String = "[subject] = String AND [new]=true"' FALLS HERE!!
Dim oTable As Interop.Outlook.Table
Try
oTable = oNS.GetDefaultFolder(Interop.Outlook.OlDefaultFolders.olFolderInbox).GetTable(filter, )
Catch ex As Exception
MsgBox(ex.ToString)
End Try
filter parameter should be 'UnRead=True' or 'New=True'...
getting a COM exception: not Valid argument
any ideas on; How To get the new mails?
any remarks regarding current code?
any ideas on how i pull inbox directly from the MailServer?
thanks again,
-j
-
Jul 16th, 2007, 10:06 AM
#4
Re: Mail Retriever for Microsoft Outlook Exchange
-
Jul 16th, 2007, 11:50 AM
#5
Re: Mail Retriever for Microsoft Outlook Exchange
You can loop through the items in your Inbox checking the items .Unread property as being True.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 17th, 2007, 03:06 AM
#6
Thread Starter
Hyperactive Member
get e-mail body
 Originally Posted by RobDog888
You can loop through the items in your Inbox checking the items .Unread property as being True.
tnx Rob, for suggesting.
weird enough.. for "[Unread]=True" and for "[Read]=true" i get same number of e-mails. nevermind...
(btw, no need for looping there, as outlook table obj is filtered by sql syntax.)
new question please..
post filtering, now that oTable has desired - unread/currDate/subject=constant.
how to get the body of the actuall e-mail???
thanks,
-j.
-
Jul 17th, 2007, 03:17 AM
#7
Re: Mail Retriever for Microsoft Outlook Exchange
oTable should have a Body field but if the email is an HTML one then it should be read from the .HTMLBody field.
As you can see, by accessing the table this way it becomes complicated. If you iterate through the folders .Items collection you can access properties, filter, display a particular item etc.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 17th, 2007, 03:41 AM
#8
Thread Starter
Hyperactive Member
Re: Mail Retriever for Microsoft Outlook Exchange
 Originally Posted by RobDog888
oTable should have a Body field but if the email is an HTML one then it should be read from the .HTMLBody field.
again, tnx for suggestin RobDog888
cant find the Body field.. think oTable has rows, representing e-mail objects. need to somehow cast the row on a 'Dim oM As Interop.Outlook.MailItem '
then oM has a oM.HTMLBody..
do you know how to do that?
 Originally Posted by RobDog888
As you can see, by accessing the table this way it becomes complicated. If you iterate through the folders .Items collection you can access properties, filter, display a particular item etc.
i can see!!! it IS complicated;
would love to try a new way around this issue..
any suggestions/example pls? (re. iterating through folder.Items that is..)
thanks,
-j.
-
Jul 17th, 2007, 03:56 AM
#9
Re: Mail Retriever for Microsoft Outlook Exchange
You can do a loop like so...
Code:
Set oInbox = oApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
For Each oEmail In oInbox.Items
If oEmail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML Then
MessageBox.Show(oEmail.HTMLBody)
Else
Messagebox.Show(oEmail.Body)
End If
Next
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 17th, 2007, 04:22 AM
#10
Thread Starter
Hyperactive Member
Re: Mail Retriever for Microsoft Outlook Exchange
 Originally Posted by RobDog888
You can do a loop like so...
many Thanks for suggesting Gansta.
i go at it like so:
vb Code:
dim oM as Interop.Outlook.MailItem
For Each oM In oFolder.Items
If oM.Subject = "SCMB Securities Lending extract" And oM.UnRead = True Then
MsgBox(oM.BodyFormat.ToString)
End If
Next
gettin the following Error
Code:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MailItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
what am i doing wrong?
-
Jul 17th, 2007, 04:25 AM
#11
Re: Mail Retriever for Microsoft Outlook Exchange
Do you have all email types in your inbox or do you have read receipts, appoint status', or non-standard emails?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 17th, 2007, 04:33 AM
#12
Thread Starter
Hyperactive Member
Re: Mail Retriever for Microsoft Outlook Exchange
donno really.. i think all types huh..
sorry to ask for help and i cannot offer more info here..
-
Jul 17th, 2007, 04:35 AM
#13
Re: Mail Retriever for Microsoft Outlook Exchange
Are you using any Imports statements at the top of the class? If so which and post the code.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 17th, 2007, 04:52 AM
#14
Thread Starter
Hyperactive Member
Re: Mail Retriever for Microsoft Outlook Exchange
statements and code below.
app falls on line 22.
thanks.
vb Code:
Imports system
Imports Microsoft.Office
Imports System.IO
Imports System.Windows.Forms
Imports System.Xml
Imports Microsoft.Office.Core
Dim objOutlook As Interop.Outlook.Application
Dim oM As Interop.Outlook.MailItem
objOutlook = New Interop.Outlook.Application
Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace
oNS = objOutlook.GetNamespace("mapi")
Dim oFolder As Interop.Outlook.MAPIFolder
oFolder = oNS.GetDefaultFolder(Interop.Outlook.OlDefaultFolders.olFolderInbox)
Dim filter As String = "[subject]=SCMB Securities Lending extract AND [unread]=true "
Dim oTable As Interop.Outlook.Table
Try
oTable = oNS.GetDefaultFolder(Interop.Outlook.OlDefaultFolders.olFolderInbox).GetTable(filter)
Catch ex As Exception
MsgBox(ex.Message)
End Try
For Each oM In oFolder.Items
If oM.Subject = "SCMB Securities Lending extract" And oM.UnRead = True Then
MsgBox(oM.BodyFormat.ToString)
End If
Next
Do Until oTable.EndOfTable
oM = oTable.FindNextRow
MsgBox(oM.HTMLBody)
Loop
-
Jul 17th, 2007, 04:55 AM
#15
Re: Mail Retriever for Microsoft Outlook Exchange
You dont need two imports statements for Office. Could be confusing VS and having it relate objects to the wrong types.
Code:
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports System.Xml
Imports Outlook = Microsoft.Office.Interop.Outlook
[color=and then fix up your code so its properly referencing the interop classes of Outlook objects.[/color]
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 17th, 2007, 05:15 AM
#16
Thread Starter
Hyperactive Member
Re: Mail Retriever for Microsoft Outlook Exchange
 Originally Posted by RobDog888
You dont need two imports statements for Office. Could be confusing VS and having it relate objects to the wrong types.
and then fix up your code so its properly referencing the interop classes of Outlook objects.
ok. thanks for pointing this out..
yr suggestion implemented below (fine?)
vb Code:
Imports system
Imports System.IO
Imports System.Windows.Forms
Imports System.Xml
Imports outlook = Microsoft.Office.Interop.Outlook
Public Class frmMain
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objOutlook As Microsoft.Office.Interop.Outlook.Application
Dim oM As Microsoft.Office.Interop.Outlook.MailItem
objOutlook = New Microsoft.Office.Interop.Outlook.Application
Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace
oNS = objOutlook.GetNamespace("mapi")
Dim oFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
oFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)
For Each oM In oFolder.Items
If oM.Subject = "SCMB Securities Lending extract" And oM.UnRead = True Then
MsgBox(oM.BodyFormat.ToString)
End If
Next
Dim filter As String = "[subject]=SCMB Securities Lending extract AND [unread]=true "
Dim oTable As Microsoft.Office.Interop.Outlook.Table
Try
oTable = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox).GetTable(filter)
Catch ex As Exception
MsgBox(ex.Message)
End Try
MsgBox(oTable.GetRowCount)
Do Until oTable.EndOfTable
oTable.FindNextRow.Item(2).ToString()
oM = oTable.FindNextRow
MsgBox(oM.HTMLBody)
Loop
objOutlook.Quit()
objOutlook = Nothing
GC.Collect()
End Sub
End Class
unfortunately, error persists
error Code:
System.InvalidCastException was unhandled
Message="Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MailItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
Source="myMailRetriever"
StackTrace:
at myMailRetriever.frmMain.frmMain_Load(Object sender, EventArgs e) in C:\Documents and Settings\jsavir\Desktop\Checked Out\myMailRetriever\myMailRetriever\myMailRetriever\frmMain.vb:line 29
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at myMailRetriever.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
-
Jul 17th, 2007, 09:32 AM
#17
Thread Starter
Hyperactive Member
found it!!! SORTED- Thanks very much
found a way.
thanks RobDog for your help
-
Jul 17th, 2007, 11:21 AM
#18
Re: [RESOLVED] Mail Retriever for Microsoft Outlook Exchange
Glad its working now for you.
Just wanted to note that if you use the Imports for a class then you dont need to keep fully qualifying it in the definition of the variables etc.
Dim objOutlook As Microsoft.Office.Interop.Outlook.Application
Could simply be ...
Dim objOutlook As Outlook.Application
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 17th, 2007, 02:40 PM
#19
Thread Starter
Hyperactive Member
Re: [RESOLVED] Mail Retriever for Microsoft Outlook Exchange
 Originally Posted by RobDog888
Glad its working now for you.
Just wanted to note that if you use the Imports for a class then you dont need to keep fully qualifying it in the definition of the variables etc.
Dim objOutlook As Microsoft.Office.Interop.Outlook.Application
Could simply be ...
Dim objOutlook As Outlook.Application
i see, i'm learnin. here . mm, so thought that is what you meant in this post:
 Originally Posted by RobDog888
You dont need two imports statements for Office. Could be confusing VS and having it relate objects to the wrong types.
and then fix up your code so its properly referencing the interop classes of Outlook objects.
sorry, what do you mean by "so its properly referencing the interop classes of Outlook objects" ??
are objects properly referenced now?
p.s
many thanks for sharing your knowledge. i appreciate your help.
-
Jan 27th, 2009, 04:00 AM
#20
New Member
Re: [RESOLVED] Mail Retriever for Microsoft Outlook Exchange
Hi I am using C#.net and facing the same problem.
How to solve it ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|