Using more than one email client

V

Vantastic

I'm developing a simple program for a friend of mine. The scenario is that he
uses 2 email clients. Lotus Notes (Default) and Outlook 2007. The problem I
am facing is that he needs to be able to send an email through Outlook. I've
used the SendObject command which will unfortunately use the default client.

Is there some way I can email with either Outlook, or a behind-the-scenes
DLL or something? As far as keeping track of what is sent it's not really an
issue as it would just send a CC to himself.

The actual content of what is being sent is a simple message body with a
Query result in excel format.

TIA
 
G

Graham Mandeno

Hi Vantastic

Try using this function:

Public Function SendOutlookMail( _
sRecipient As String, _
sSubject As String, _
sMessage As String, _
Optional sAttachment As String, _
Optional fPreview As Boolean = True) _
As Boolean
' use late binding so as not to require a library reference
Dim oOutlook As Object ' Outlook.Application
Dim oMessage As Object ' Outlook.MailItem
Const olMailItem = 0
'On Error GoTo ProcErr
Set oOutlook = CreateObject("Outlook.Application")
Set oMessage = oOutlook.CreateItem(olMailItem)
With oMessage
.To = sRecipient
.Subject = sSubject
.Body = sMessage
If Len(sAttachment) > 0 Then
.Attachments.Add (sAttachment)
End If
.Save
If fPreview Then
.Display
Else
.Send
End If
End With
SendOutlookMail = True
ProcEnd:
On Error Resume Next
Set oOutlook = Nothing
Set oMessage = Nothing
Exit Function
ProcErr:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description, _
vbExclamation, "SendOutlookEmail failed"
Resume ProcEnd
End Function
 
V

Vantastic

Graham, thank you VERY much for this... it worked a treat... I added the CC
and BCC fields in there too with no problem :)

Fantastic work!

--

Graham Mandeno said:
Hi Vantastic

Try using this function:

Public Function SendOutlookMail( _
sRecipient As String, _
sSubject As String, _
sMessage As String, _
Optional sAttachment As String, _
Optional fPreview As Boolean = True) _
As Boolean
' use late binding so as not to require a library reference
Dim oOutlook As Object ' Outlook.Application
Dim oMessage As Object ' Outlook.MailItem
Const olMailItem = 0
'On Error GoTo ProcErr
Set oOutlook = CreateObject("Outlook.Application")
Set oMessage = oOutlook.CreateItem(olMailItem)
With oMessage
.To = sRecipient
.Subject = sSubject
.Body = sMessage
If Len(sAttachment) > 0 Then
.Attachments.Add (sAttachment)
End If
.Save
If fPreview Then
.Display
Else
.Send
End If
End With
SendOutlookMail = True
ProcEnd:
On Error Resume Next
Set oOutlook = Nothing
Set oMessage = Nothing
Exit Function
ProcErr:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description, _
vbExclamation, "SendOutlookEmail failed"
Resume ProcEnd
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top