Sub SendMail(mlMsg, mlRecepients, mlSubject, Optional mlCC,Optional mlAttachments)
'If you are using Option Explicit you will have to declare all variables below since I didn't ...
Set myItem = CreateObject("Redemption.SafeMailItem")
Set olkApp = New Outlook.Application
Set tmpItem = olkApp.CreateItem(0)
myItem.Item = tmpItem
If Not IsArray(mlRecepients) Then
If mlRecepients = "Self" Then
Set CU = CreateObject("Redemption.SafeCurrentUser")
mlRecepients = CU.Name
CU.Cleanup 'do call cleanup, otherwise Outlook might have trouble properly closing down
Set CU = Nothing
End If
myItem.Recipients.Add mlRecepients
Else
For i = 1 To UBound(mlRecepients)
myItem.Recipients.Add mlRecepients(i)
Next i
End If
If Not IsMissing(mlCC) Then
If Not IsArray(mlCC) Then
Set tmp = myItem.Recipients.Add(mlCC)
tmp.Type = 2
Else
For i = 1 To UBound(mlCC)
Set tmp = myItem.Recipients.Add(mlCC(i))
tmp.Type = 2
Next i
End If
End If
If Not IsMissing(mlAttachments) Then
If Not IsArray(mlAttachments) Then
myItem.Attachments.Add mlAttachments
Else
For i = 1 To UBound(mlRecepients)
myItem.Attachments.Add mlAttachments(i)
Next i
End If
End If
myItem.HTMLBody = mlMsg
myItem.Subject = mlSubject
On Error Resume Next
myItem.Recipients.ResolveAll
myItem.Send
If Err.Number <> 0 Then
msgPrompt = "Email could not be sent. Probably wrong recipient or insufficient space ..."
msgPrompt = msgPrompt & Chr(13) & "The message will be diplayed instead."
MsgTitle = "Send Email"
MsgBox msgPrompt, vbExclamation + vbOKOnly, MsgTitle
myItem.Display
End If
Set myItem = Nothing
Set olkApp = Nothing
Set tmpItem =Nothing
End Sub