Function CDOSendEmail(varFrom As Variant, strTo As String, strSubj As String, strMess As String)
Dim strDefaultFrom As String
Dim objMess As Object
Set objMess = CreateObject("CDO.Message")
' This is your default FROM address, and to be used if varFrom is Null or Empty
strDefaultFrom = "[email protected]"
' Subject
objMess.Subject = strSubj
' Message
objMess.textbody = strMess
' Determine if varFrom is Null/Empty and use default address,
' otherwise use the From address passed through the function call
objMess.From = IIf(Nz(varFrom, "") = "", strDefaultFrom, varFrom)
' To
objMess.To = strTo
' This is a simple example... you can do a lot more
' Send it
objMess.Send
' Clear the object variable
Set objMess = Nothing
End Function
|