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 Public Function QuickMail(ByVal jTo As Variant, _ Optional ByVal jCC As Variant, _ Optional ByVal jBCC As Variant, _ Optional ByVal jSubject As String, _ Optional ByVal jBody As String) As String Dim tmpTo As String Dim tmpCC As String Dim tmpBCC As String Dim tmpSubject As String Dim tmpBody As String Dim strMailTo As String 'see what kind of variable was passed into the variant Select Case VarType(jTo) 'if just a string, use it Case vbString tmpTo = jTo 'if an array, join it into a string Case vbArray + vbString tmpTo = Join(jTo, ";") 'raise an "error" Case Else QuickMail = "ERROR: jTo Invalid Data Type" Exit Function End Select Select Case VarType(jCC) Case vbString tmpCC = "&cc=" & jCC Case vbArray + vbString tmpCC = "&cc=" & Join(jCC, ";") Case vbError tmpCC = vbNullString Case Else QuickMail = "ERROR: jCC Invalid Data Type" Exit Function End Select Select Case VarType(jBCC) Case vbString tmpBCC = "&bcc=" & jBCC Case vbArray + vbString tmpBCC = "&bcc=" & Join(jBCC, ";") Case vbError tmpBCC = vbNullString Case Else QuickMail = "ERROR: jBCC Invalid Data Type" Exit Function End Select If jSubject <> vbNullString Then tmpSubject = "&subject=" & jSubject Else tmpSubject = vbNullString End If If jBody <> vbNullString Then tmpBody = "&body=" & jBody Else tmpBody = vbNullString End If 'make your mailto statement. MSDN help file index 'of "Mailto Protocol" strMailTo = "mailto:" & tmpTo & tmpSubject & tmpBody & _ tmpCC & tmpBCC 'this will launch the statement from the default mail handler Call ShellExecute(0&, vbNullString, strMailTo, _ vbNullString, vbNullString, vbNormalFocus) End Function Private Sub Command1_Click() Dim strTo(1 To 4) As String Dim strCC(1 To 10) As String Dim strBCC As String Dim strSubject As String Dim strBody As String Dim strMessages As String Dim intX As Integer 'this function allows you to pass an array 'of strings, or just a regular string 'using an array: strTo(1) = "jay@kreusch.com" strTo(2) = "jay@entech-inc.com" strTo(3) = "jkreusc@entech-inc.com" strTo(4) = "Yours@email.com" 'Creating an array For intX = 1 To 10 strCC(intX) = "user_" & intX & "@domain.com" Next 'using a normal string (separate with semicolons" strBCC = "1@abc.com;2@xyz.com;hi@bye.com" 'assign your subject and body strBody = "This is your body paragraph" 'call the function strMessages = QuickMail(strTo(), strCC(), strBCC, _ strSubject, strBody) 'see if it passed back an error If strMessages <> "" Then MsgBox strMessages End If End Sub Name: Send mail from default email client! Outlook, Netscape, Eudora, Whatever By: Jay Kreusch Inputs:Provide it either a string or array of addresses, the subject, and the body. Side Effects: No attachments can be added. |