I cut a mail function off the m'soft site. Has always worked. However,
I would like to include error codes returned by the sendmail Fn and
be able to understand what they mean. I had my first occasion to
experience a failure and got a code of 2??? Would like to know
just what that means.
Here's how I call the fn...
Result = SendMail((F!Subject), (F!To), (F!CC), (F!Attach),
(F!Message))
And here's the fn.....
Function SendMail (sSubject As String, sTo As String, sCC As String,
sAttach As String, sMessage As String)
Dim i, cTo, cCC, cAttach ' variables holding counts
Dim MAPI_Message As MAPIMessage
' Count the number of items in each piece of the mail message
cTo = CountTokens(sTo, ";")
cCC = CountTokens(sCC, ";")
cAttach = CountTokens(sAttach, ";")
' Create arrays to store the semicolon delimited mailing
' .. information after it is parsed
ReDim rTo(0 To cTo) As String
ReDim rCC(0 To cCC) As String
ReDim rAttach(0 To cAttach) As String
' Parse the semicolon delimited information into the arrays.
ParseTokens rTo(), sTo, ";"
ParseTokens rCC(), sCC, ";"
ParseTokens rAttach(), sAttach, ";"
' Create the MAPI Recip structure to store all the To and CC
' .. information to be passed to the MAPISendMail function
ReDim MAPI_Recip(0 To cTo + cCC - 1) As MapiRecip
' Setup the "TO:" recipient structures
For i = 0 To cTo - 1
MAPI_Recip(i).Name = rTo(i)
MAPI_Recip(i).RecipClass = MAPI_TO
Next i
' Setup the "CC:" recipient structures
For i = 0 To cCC - 1
MAPI_Recip(cTo + i).Name = rCC(i)
MAPI_Recip(cTo + i).RecipClass = MAPI_CC
Next i
' Create the MAPI File structure to store all the file
attachment
' .. information to be passed to the MAPISendMail function
ReDim MAPI_File(0 To cAttach) As MapiFile
' Setup the file attachment structures
MAPI_Message.FileCount = cAttach
For i = 0 To cAttach - 1
MAPI_File(i).Position = -1
MAPI_File(i).PathName = rAttach(i)
Next i
' Set the mail message fields
MAPI_Message.Subject = sSubject
MAPI_Message.NoteText = sMessage
MAPI_Message.RecipCount = cTo + cCC
' Send the mail message
SendMail = MAPISendMail(0&, 0&, MAPI_Message, MAPI_Recip(0),
MAPI_File(0), MAPI_LOGON_UI, 0&)
End Function