send outlook message

mojo
09-13-2000, 10:08 PM
I have the following code which creates an email message using outlook:

Private Sub CBBen_Click()
Dim aplOutlook As Outlook.Application
Dim MailMessage As MailItem
Dim CName As String
Dim JNumber As Integer
CName = FrmMail.TBCName.Text
JNumber = FrmMail.TBJobnumber.Text

Set aplOutlook = CreateObject("Outlook.Application")
Set MailMessage = aplOutlook.CreateItem(olMailItem)

With MailMessage
.To = "bav"
.Subject = "JobTracker Notice: Job Complete"
.Body = "Job number " & JNumber & " for " & CName & " has been completed."
.Send
End With

MsgBox "Message Sent"

Set MailMessage = Nothing
Set aplOutlook = Nothing

End Sub

It works fine except that it only puts the message in the outlook Outbox. Is there another piece of code I have to use in order to actually send the message?

ps I have referenced MS Outlook 9.0 Object Library

Thanks

mojo

whelanp
09-14-2000, 06:00 AM
I use the following code which works fine,

The main differences seem to be my initial setup of the email and the recipient settings.

Public Sub DoEmail(byval strMailAddr As String)

On Error GoTo ProcErr

Dim olApp As Outlook.Application
Dim olSpace As Outlook.NameSpace
Dim olTopFld As Outlook.MAPIFolder ' Object representing top most folder we're looking in
Dim olFldOut As Outlook.MAPIFolder '
Dim olMail As Outlook.MailItem '

Set olApp = New Outlook.Application
Set olSpace = olApp.GetNamespace("MAPI")

Set olTopFld = olSpace.Folders("Mailbox - Application Server")
Set olFldOut = olTopFld.Folders("Outbox")

Set olMail = olFldOut.Items.Add(olMailItem)

With olMail

With .Recipients
.Add strMailAddr
.ResolveAll
End With

.Subject = "Subject"
.Body = "Body"
.Importance = olImportanceHigh
.Send
End With


ProcExit:
Exit Sub

ProcErr:
MsgBox "Error: " & Err.Description
Resume ProcExit
End Sub


Hope this helps.

Dazz
09-14-2000, 09:46 AM
I just logged on to pose a question about automatically sending an e:mail through outlook.

Don't you just love this place.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum