|
-
Mar 26th, 2003, 04:25 PM
#1
Thread Starter
Hyperactive Member
.NET vs VB6 and OUTLOOK
This worked in VB6 to fill a list box..
Private Sub Command2_Click()
Dim Counter As Long
Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
For Each olAL In olNS.AddressLists
For Each olAE In olAL.AddressEntries
Counter = Counter + 1
Label8.Caption = Counter
ListView1.AddItem (olAE.Name)
Next
Next
End Sub
BUT.... syntex checks with .NET
What am I doing wrong.. Help
-
Mar 26th, 2003, 05:58 PM
#2
Fanatic Member
i would suggest you take a look at the many articles that deal with interacting with external .net applications and unmanaged code.
-
Mar 27th, 2003, 06:16 AM
#3
Thread Starter
Hyperactive Member
Thanks .. Actually ... there is a sea of books.. but no practical example. I was hoping someone had already tried and succeeded with this.
-
Mar 27th, 2003, 12:30 PM
#4
yay gay
first of all vb.net doesnt support the "Set" just remove it and maybe it works fine
\m/  \m/
-
Mar 27th, 2003, 01:13 PM
#5
Sleep mode
after you finish building your proj in .net , reference outlook dll to your proj and instantiate an obje then use it something like this :
Dim otObj as new outlook..... (not sure of synatx though)
-
Mar 28th, 2003, 12:37 AM
#6
Hyperactive Member
Here you go:
For one simple email, try this:
Code:
Private Sub lnkSendEMail_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) lnkSendEMail.LinkClicked
If Trim(txtEmail.Text) <> "" Then System.Diagnostics.Process.Start("mailto:" & txtEmail.Text)
End Sub
For more complex emailing - including converting it to HTML use this:
Code:
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim intIndex As Integer
Dim outApp As New Outlook.Application()
Dim wrdApp As New Word.Application()
Dim ThisClient As stsClients.ClientRecord
Dim olMail As Outlook.MailItem
Dim wrdDocOri As Word.Document
Dim wrdDocNew As Word.Document
Dim wrdSelection As Word.Selection
Dim I As Integer
ProgressBar1.Value = 0
ProgressBar1.Maximum = UBound(arrClientIDs) + 1
If File.Exists(txtFileName.Text) = False Then
MessageBox.Show("Cannot locate file: " & txtFileName.Text & vbCrLf & vbCrLf & _
"Please check and try again.", "File Missiing", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
wrdApp.Visible = False
For intIndex = 0 To UBound(arrClientIDs)
If Confirmation = False Or _
ConfirmationLetterSentGet(arrClientIDs(intIndex), ItemDate) = False Then
wrdDocOri = wrdApp.Documents.Open(txtFileName.Text)
wrdSelection = wrdApp.Selection
olMail = outApp.CreateItem(Outlook.OlItemType.olMailItem)
ThisClient = GetClient(gconDatabase, arrClientIDs(intIndex))
olMail.To = ThisClient.Email
olMail.Subject = txtSubject.Text
If chkDear.Checked = True Then
wrdSelection.TypeText("Dear ")
End If
If chkTitle.Checked = True Then
wrdSelection.TypeText(ThisClient.Title & " ")
End If
If chkFirst.Checked = True Then
wrdSelection.TypeText(ThisClient.First & " ")
End If
If chkSurname.Checked = True Then
wrdSelection.TypeText(ThisClient.Last & " ")
End If
If (chkDear.Checked = True) Or (chkTitle.Checked = True) _
Or (chkFirst.Checked = True) Or (chkSurname.Checked = True) Then
wrdSelection.TypeText(vbCrLf & " ")
End If
If nudBlank02.Value > 0 Then
For I = 1 To nudBlank02.Value
wrdSelection.TypeText(vbCrLf & " ")
Next
End If
If chkHTML.Checked = True Then
wrdDocOri.SaveAs("c:\trash\email" & ProgressBar1.Value & ".htm", wdFormatHTML)
CType(wrdDocOri, Word._Document).Close()
Dim fs As New System.IO.FileStream("c:\trash\email" & ProgressBar1.Value & ".htm", IO.FileMode.Open)
Dim sr As New System.IO.StreamReader(fs)
Dim strHTML As String
strHTML = sr.ReadToEnd()
olMail.HTMLBody = strHTML
Else
olMail.Body = wrdDocNew.Content.Text
End If
' Send eMail
Try
If Confirmation = True Then
olMail.ReadReceiptRequested = True
End If
CType(olMail, Outlook._MailItem).Send()
' Update Confirmation Field
If Confirmation = True Then
ConfirmationLetterSentSet(arrClientIDs(intIndex), ItemDate, True)
End If
Catch
End Try
'Release References
Try
CType(wrdDocOri, Word._Document).Close()
File.Delete("c:\trash\email01.htm")
Catch
' Do nothing
End Try
olMail = Nothing
'wrdDoc.Close()
End If
ProgressBar1.Value = ProgressBar1.Value + 1
Application.DoEvents()
Next
wrdDocOri = Nothing
wrdApp = Nothing
outApp = Nothing
GC.Collect()
MessageBox.Show("Emails have been sent to your outbox.", "Emails Sent", MessageBoxButtons.OK, MessageBoxIcon.Information)
Application.DoEvents()
End Sub
HAVE FUN!
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer
Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia
www.stingrae.com.au
Developer of Arnold - Gym & Martial Arts Database Management System
www.gymdatabase.com.au
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
|