June 14, 2001

Send Mail (Uses Outlook to feed data)

Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory _
As String, ByVal nShowCmd As Long) As Long

Private Const SW_SHOWNORMAL = 1

Public Sub SendMail(Optional Address As String, _
Optional Subject As String, Optional Body As String, _
Optional CC As String, Optional BCC As String)

Dim strCommand As String

'Build up the mail string
If Len(Subject) Then strCommand = "&Subject=" & Subject
If Len(Body) Then strCommand = strCommand & "&Body=" & Body
If Len(CC) Then strCommand = strCommand & "&CC=" & CC
If Len(BCC) Then strCommand = strCommand & "&BCC=" & BCC

'Replace the first ampersand, if any,
'with a question mark
If Len(strCommand) Then
Mid(strCommand, 1, 1) = "?"
End If

'Add mailto: command and main e-mail
'address to the command string
strCommand = "mailto:" & Address & strCommand

'Execute command via the API
Call ShellExecute(Me.hwnd, "open", strCommand, _
vbNullString, vbNullString, SW_SHOWNORMAL)

End Sub

Private Sub Command1_Click()
Call SendMail("majit@hotmail.com", "Test Mail", _
"Hope you see this!", _
"majit@hotmail.com", "majit@hotmail.com")
End Sub