umm does vs2003 integrate with outlook anyhow? I wanna write an app that opens a bunch of emails and I dont know if it's directly supported by framework 1.1 classes or not :D give me some clues.........
Printable View
umm does vs2003 integrate with outlook anyhow? I wanna write an app that opens a bunch of emails and I dont know if it's directly supported by framework 1.1 classes or not :D give me some clues.........
no, buy you can reference outlook for automation via COM
This should get you started.
VB Code:
'Add a reference to MS Outlook xx.0 Object Library 'Project > Add Reference... > COM tab > select MS Outlook 11.0 Object library Public Class Form1 Inherits System.Windows.Forms.Form Public moApp As Outlook.Application Public moNS As Outlook.NameSpace '"Windows Form Designer generated code" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim oFolder As Outlook.MAPIFolder Dim oEmail As Outlook.MailItem oFolder = moNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) If oFolder.Items.Count > 0 Then oEmail = oFolder.Items.Item(1) MessageBox.Show(oEmail.Subject, ".NET Outlook Demo", MessageBoxButtons.OK, MessageBoxIcon.Information) Else MessageBox.Show("No items found!", ".NET Outlook Demo", MessageBoxButtons.OK, MessageBoxIcon.Information) End If oEmail = Nothing oFolder = Nothing End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load moApp = New Outlook.Application moNS = moApp.GetNamespace("MAPI") End Sub End Class
ah 2 thumbs up:D thanks a lot... spent 40 mins in the vb6 editor of outlook and only figured this much out
Dim mee As MAPIFolder
Set mee = Outlook.Session.Folders.Item(2)
Dim inbox As Object
Set inbox = mee .Folders.Item(2)
Dim i As Integer
Dim s As String
For i = 1 To inbox.Items.Count
s = s & inbox.Items.Item(i)
Next
umm ok so does outlook have to be open for all these to work?
I"m gonna try working on this later... midterm tomorrow, but thanks for the help
You need to create a New instance of the Application Object which basically opens Outlook.
What are you trying to do? Maybe a better way?
ummQuote:
Originally Posted by RobDog888
one particular folder in one of the accounts that I have receives a bunch of mails. I need to open each mail and locate every url in it (basically find all the URLs in all the emails that I have in that folder). Then I try to download the http page that the url points to...... dont ask why :D
But I want to ask why? :D
I thought that maybe you were trying to replicate the welcome screen in XP where it displays the number of unread
new emails received.
Are your emails all HTML body format? or a combination of pain/rich/html text?
umm not sure what I'll be getting. I expect them to be HTML... I mean I can parse through it myself. My problem is that I dont know how to open each mail. If I can examine each email one by one then I can do the rest...Quote:
Originally Posted by RobDog888
as to why :D there is this company that sends advertisements out and if I subscribe and "read" each email (by clicking on links) I get 2 cents per email... so if I do a lot of it with a program I get a few dollars a month:D
Oh, ok. so when so I get my cut? :lol:
I'll expand on the code I posted to enumerate the items in this folder called ???
Give me a few minutes. I need to enter in my time card so I can get paid :D
Will this be for Outlook 2003 only?
I'm almost done but if I need to handle different version of Outlook then I need to know. :D
Ps, you get to do the parsing ;)
Ok, I did my part now its up to you :D
:DVB Code:
Option Explicit On 'Add a reference to MS Outlook xx.0 Object Library 'Project > Add Reference... > COM tab > select MS Outlook 11.0 Object library Imports Microsoft.Office.Interop Public Class Form1 Inherits System.Windows.Forms.Form #Region " Outlook Variables " Private moApp As Outlook.Application Private moNS As Outlook.NameSpace Private moFolder As Outlook.MAPIFolder Private mbTerminate As Boolean #End Region #Region " Outlook Constants " Private Const olMail = 43 Private Const olFormatUnspecified = 0 Private Const olFormatPlain = 1 Private Const olFormatHTML = 2 Private Const olFormatRichText = 3 #End Region #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents btnClose As System.Windows.Forms.Button Friend WithEvents btnBrowse As System.Windows.Forms.Button Friend WithEvents txtFolderPath As System.Windows.Forms.TextBox Friend WithEvents lblFolderPath As System.Windows.Forms.Label Friend WithEvents btnParse As System.Windows.Forms.Button <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.btnClose = New System.Windows.Forms.Button Me.btnBrowse = New System.Windows.Forms.Button Me.txtFolderPath = New System.Windows.Forms.TextBox Me.lblFolderPath = New System.Windows.Forms.Label Me.btnParse = New System.Windows.Forms.Button Me.SuspendLayout() ' 'btnClose ' Me.btnClose.Location = New System.Drawing.Point(208, 96) Me.btnClose.Name = "btnClose" Me.btnClose.TabIndex = 0 Me.btnClose.Text = "&Close" ' 'btnBrowse ' Me.btnBrowse.Location = New System.Drawing.Point(264, 40) Me.btnBrowse.Name = "btnBrowse" Me.btnBrowse.Size = New System.Drawing.Size(20, 20) Me.btnBrowse.TabIndex = 1 Me.btnBrowse.Text = "..." ' 'txtFolderPath ' Me.txtFolderPath.Location = New System.Drawing.Point(16, 40) Me.txtFolderPath.Name = "txtFolderPath" Me.txtFolderPath.Size = New System.Drawing.Size(248, 20) Me.txtFolderPath.TabIndex = 2 Me.txtFolderPath.Text = "" ' 'lblFolderPath ' Me.lblFolderPath.Location = New System.Drawing.Point(16, 24) Me.lblFolderPath.Name = "lblFolderPath" Me.lblFolderPath.Size = New System.Drawing.Size(100, 16) Me.lblFolderPath.TabIndex = 3 Me.lblFolderPath.Text = "Folder Path:" ' 'btnParse ' Me.btnParse.Location = New System.Drawing.Point(124, 96) Me.btnParse.Name = "btnParse" Me.btnParse.TabIndex = 4 Me.btnParse.Text = "Parse Links" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 126) Me.Controls.Add(Me.btnParse) Me.Controls.Add(Me.lblFolderPath) Me.Controls.Add(Me.txtFolderPath) Me.Controls.Add(Me.btnBrowse) Me.Controls.Add(Me.btnClose) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle Me.MaximizeBox = False Me.Name = "Form1" Me.Text = "Outlook Link Parser™" Me.ResumeLayout(False) End Sub #End Region Private Sub btnParse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnParse.Click Dim oEmail As Outlook.MailItem Dim i As Integer For i = 1 To moFolder.Items.Count 'Check for mailitems only and not undeliverable errors, meeting requests, or other non-mail items. If moFolder.Items(i).Class = olMail Then oEmail = moFolder.Items.Item(i) 'Check for body format type Select Case oEmail.BodyFormat Case Outlook.OlBodyFormat.olFormatUnspecified 'Try to parse using plain text format? Case Outlook.OlBodyFormat.olFormatPlain 'Try to parse text If oEmail.Body.IndexOf("http://www.vbforums.com") > 0 Then Console.WriteLine(oEmail.Body.Substring(oEmail.Body.IndexOf("http://www.vbforums.com"), 23)) End If Case Outlook.OlBodyFormat.olFormatHTML 'Try to parse html If oEmail.HTMLBody.IndexOf("http://www.vbforums.com") > 0 Then 'Do other stuff '... End If Case Outlook.OlBodyFormat.olFormatRichText 'Try to parse RTF End Select oEmail = Nothing End If Next oEmail = Nothing Me.Activate() MessageBox.Show("Done!", "Outlook Link Parser™", MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load mbTerminate = False moApp = GetObject(, "Outlook.Application") If moApp Is Nothing Then moApp = New Outlook.Application mbTerminate = True End If moNS = moApp.GetNamespace("MAPI") End Sub Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click moFolder = moNS.PickFolder If Not moFolder Is Nothing Then txtFolderPath.Text = moFolder.FolderPath End If Me.Activate() End Sub Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click Me.Dispose() End Sub Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing moFolder = Nothing moNS = Nothing If Not (moApp Is Nothing) And (mbTerminate = True) Then moApp.Quit() End If moApp = Nothing End Sub End Class
whoa thats a lot of code and effort:D:D:D:D:D thanks!!!!!!!!! I'll see what I can make out of it :afrog: :afrog: :afrog: :afrog:
hmm feeling dumb:D
I added that com reference, but it says it cant find the namespace on the imports line :
Imports Microsoft.Office.Interop
what else do I need to add :rolleyes:
:thumb: No effort when you have been automating Outlook for a few years. I wrote it in a few minutes during lunch.
Automating Office Apps is my FortÉ :D
Consider it payback for all the help you have given me with learning VB.NET ;)
Ok, I pasted in my code into an existing Outlook test project and rebuilt and got your error.
I will connect to work and get my source project and see what the root namespace is.
Hold on....
:) :) thanksQuote:
Originally Posted by RobDog888
I'm not in a hurry though, so take your time... I'll probably have to wait till the weekend :)
Ok, this must be some weird .NET thing now. .Interop is not showing on my home system, but it does for
my work system. Both are the same versions and Office versions. Only difference is my work system is
XP SP2 and home is XP SP1.
What happened to Wednesday, Thursday, and Friday? I want to work where you work. 5 day weekends! :DQuote:
Originally Posted by MrPolite
Ok, I'll check more into it tomorrow at work. ;)
Ok, got it working but still cant explain the .Interop issue.
VB Code:
Imports Microsoft.Office '... '... Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load mbTerminate = False Try moApp = GetObject(, "Outlook.Application") Catch ex As Exception If moApp Is Nothing Then moApp = New Outlook.Application mbTerminate = True End If End Try moNS = moApp.GetNamespace("MAPI") End Sub
w00t it's working!! unbelievable hah:D
p.s. I didnt even need Office.Interop. It compiled without it!
one thing, every time I do this outlook asks me whether I should allow the program to access the data or not. Is there a way to stop that?
:afrog: :afrog: :afrog:
:thumb:'s
But you used the "Imports Microsoft.Office" though? ;)
You can stop the Outlook Security Prompt by re-writing your app as an Trusted Outlook Add-In using the
IDExtensibility2 implements (usually a pain).
With .NET I do believe there is another option, but I cant remember right now. I vaguely remember reading
something about new VS.NET features/capabilities. I havent got too deep into .NET and Office yet. :(
Not much time lately.