Type MAPIMessage
Reserved As Long
Subject As String
NoteText As String
MessageType As String
DateReceived As String
ConversationID As String
Flags As Long
RecipCount As Long
FileCount As Long
End Type
Type MapiRecip
Reserved As Long
RecipClass As Long
Name As String
Address As String
EIDSize As Long
EntryID As String
End Type
Type MapiFile
Reserved As Long
Flags As Long
Position As Long
PathName As String
FileName As String
FileType As String
End Type
Declare Function MAPILogon Lib "MAPI32.DLL" (ByVal UIParam&, ByVal user$, _
ByVal Password$, ByVal Flags&, ByVal Reserved&, Session&) As Long
Declare Function MAPILogoff Lib "MAPI32.DLL" (ByVal Session&, ByVal _
UIParam&, ByVal Flags&, ByVal Reserved&) As Long
Declare Function BMAPIReadMail Lib "MAPI32.DLL" (lMsg&, nRecipients&, _
nFiles&, ByVal Session&, ByVal UIParam&, MessageID$, ByVal Flag&, ByVal _
Reserved&) As Long
Declare Function BMAPIGetReadMail Lib "MAPI32.DLL" (ByVal lMsg&, Message As _
MAPIMessage, Recip() As MapiRecip, File() As MapiFile, Originator As _
MapiRecip) As Long
Declare Function MAPIFindNext Lib "MAPI32.DLL" Alias "BMAPIFindNext" (ByVal _
Session&, ByVal UIParam&, MsgType$, SeedMsgID$, ByVal Flag&, ByVal _
Reserved&, MsgID$) As Long
Declare Function MAPISendDocuments Lib "MAPI32.DLL" (ByVal UIParam&, ByVal _
DelimStr$, ByVal FilePaths$, ByVal FileNames$, ByVal Reserved&) As Long
Declare Function MAPIDeleteMail Lib "MAPI32.DLL" (ByVal Session&, ByVal _
UIParam&, ByVal MsgID$, ByVal Flags&, ByVal Reserved&) As Long
Declare Function MAPISendMail Lib "MAPI32.DLL" Alias "BMAPISendMail" (ByVal _
Session&, ByVal UIParam&, Message As MAPIMessage, Recipient() As MapiRecip, _
File() As MapiFile, ByVal Flags&, ByVal Reserved&) As Long
Declare Function MAPISaveMail Lib "MAPI32.DLL" Alias "BMAPISaveMail" (ByVal _
Session&, ByVal UIParam&, Message As MAPIMessage, Recipient() As MapiRecip, _
File() As MapiFile, ByVal Flags&, ByVal Reserved&, MsgID$) As Long
Declare Function BMAPIAddress Lib "MAPI32.DLL" (lInfo&, ByVal Session&, _
ByVal UIParam&, Caption$, ByVal nEditFields&, Label$, nRecipients&, Recip() _
As MapiRecip, ByVal Flags&, ByVal Reserved&) As Long
Declare Function BMAPIGetAddress Lib "MAPI32.DLL" (ByVal lInfo&, ByVal _
nRecipients&, Recipients() As MapiRecip) As Long
Declare Function MAPIDetails Lib "MAPI32.DLL" Alias "BMAPIDetails" (ByVal _
Session&, ByVal UIParam&, Recipient As MapiRecip, ByVal Flags&, ByVal _
Reserved&) As Long
Declare Function MAPIResolveName Lib "MAPI32.DLL" Alias "BMAPIResolveName" _
(ByVal Session&, ByVal UIParam&, ByVal UserName$, ByVal Flags&, ByVal _
Reserved&, Recipient As MapiRecip) As Long
Global Const SUCCESS_SUCCESS = 0
Global Const MAPI_USER_ABORT = 1
Global Const MAPI_E_USER_ABORT = MAPI_USER_ABORT
Global Const MAPI_E_FAILURE = 2
Global Const MAPI_E_LOGIN_FAILURE = 3
Global Const MAPI_E_LOGON_FAILURE = MAPI_E_LOGIN_FAILURE
Global Const MAPI_E_DISK_FULL = 4
Global Const MAPI_E_INSUFFICIENT_MEMORY = 5
Global Const MAPI_E_BLK_TOO_SMALL = 6
Global Const MAPI_E_TOO_MANY_SESSIONS = 8
Global Const MAPI_E_TOO_MANY_FILES = 9
Global Const MAPI_E_TOO_MANY_RECIPIENTS = 10
Global Const MAPI_E_ATTACHMENT_NOT_FOUND = 11
Global Const MAPI_E_ATTACHMENT_OPEN_FAILURE = 12
Global Const MAPI_E_ATTACHMENT_WRITE_FAILURE = 13
Global Const MAPI_E_UNKNOWN_RECIPIENT = 14
Global Const MAPI_E_BAD_RECIPTYPE = 15
Global Const MAPI_E_NO_MESSAGES = 16
Global Const MAPI_E_INVALID_MESSAGE = 17
Global Const MAPI_E_TEXT_TOO_LARGE = 18
Global Const MAPI_E_INVALID_SESSION = 19
Global Const MAPI_E_TYPE_NOT_SUPPORTED = 20
Global Const MAPI_E_AMBIGUOUS_RECIPIENT = 21
Global Const MAPI_E_AMBIG_RECIP = MAPI_E_AMBIGUOUS_RECIPIENT
Global Const MAPI_E_MESSAGE_IN_USE = 22
Global Const MAPI_E_NETWORK_FAILURE = 23
Global Const MAPI_E_INVALID_EDITFIELDS = 24
Global Const MAPI_E_INVALID_RECIPS = 25
Global Const MAPI_E_NOT_SUPPORTED = 26
Global Const MAPI_ORIG = 0
Global Const MAPI_TO = 1
Global Const MAPI_CC = 2
Global Const MAPI_BCC = 3
Global Const MAPI_LOGON_UI = &H1
Global Const MAPI_NEW_SESSION = &H2
Global Const MAPI_FORCE_DOWNLOAD = &H1000
Global Const MAPI_LOGOFF_SHARED = &H1
Global Const MAPI_LOGOFF_UI = &H2
Global Const MAPI_DIALOG = &H8
Global Const MAPI_UNREAD_ONLY = &H20
Global Const MAPI_GUARANTEE_FIFO = &H100
Global Const MAPI_ENVELOPE_ONLY = &H40
Global Const MAPI_PEEK = &H80
Global Const MAPI_BODY_AS_FILE = &H200
Global Const MAPI_SUPPRESS_ATTACH = &H800
Global Const MAPI_AB_NOMODIFY = &H400
Global Const MAPI_OLE = &H1
Global Const MAPI_OLE_STATIC = &H2
Global Const MAPI_UNREAD = &H1
Global Const MAPI_RECEIPT_REQUESTED = &H2
Global Const MAPI_SENT = &H4
Function CopyFiles(MfIn As MapiFile, MfOut As MapiFile) As Long
MfOut.FileName = MfIn.FileName
MfOut.PathName = MfIn.PathName
MfOut.Reserved = MfIn.Reserved
MfOut.Flags = MfIn.Flags
MfOut.Position = MfIn.Position
MfOut.FileType = MfIn.FileType
CopyFiles = 1&
End Function
Function CopyRecipient(MrIn As MapiRecip, MrOut As MapiRecip) As Long
MrOut.Name = MrIn.Name
MrOut.Address = MrIn.Address
MrOut.EIDSize = MrIn.EIDSize
MrOut.EntryID = MrIn.EntryID
MrOut.Reserved = MrIn.Reserved
MrOut.RecipClass = MrIn.RecipClass
CopyRecipient = 1&
End Function
Function MAPIAddress(Session As Long, UIParam As Long, Caption As String, _
nEditFields As Long, Label As String, nRecipients As Long, Recips() As _
MapiRecip, Flags As Long, Reserved As Long) As Long
Dim Info&
Dim rc&
Dim nRecips As Long
ReDim Rec(0 To nRecipients) As MapiRecip
nRecips = nRecipients
For i = 0 To nRecipients - 1
Ignore& = CopyRecipient(Recips(i), Rec(i))
Next i
rc& = BMAPIAddress(Info&, Session&, UIParam&, Caption$, nEditFields&, _
Label$, nRecips&, Rec(), Flags, 0&)
If (rc& = SUCCESS_SUCCESS) Then
nRecipients = nRecips
If (nRecipients > 0) Then
ReDim Rec(0 To nRecipients - 1) As MapiRecip
rc& = BMAPIGetAddress(Info&, nRecipients&, Rec())
ReDim Recips(0 To nRecipients - 1) As MapiRecip
For i = 0 To nRecipients - 1
Ignore& = CopyRecipient(Rec(i), Recips(i))
Next i
End If
End If
MAPIAddress = rc&
End Function
Function MAPIReadMail(Session As Long, UIParam As Long, MessageID As _
String, Flags As Long, Reserved As Long, Message As MAPIMessage, Orig As _
MapiRecip, RecipsOut() As MapiRecip, FilesOut() As MapiFile) As Long
Dim Info&
Dim nFiles&, nRecips&
rc& = BMAPIReadMail(Info&, nRecips, nFiles, Session, 0, MessageID, _
Flags, Reserved)
If (rc& = SUCCESS_SUCCESS) Then
If (nRecips = 0) Then nRecips = 1
If (nFiles = 0) Then nFiles = 1
ReDim Recips(0 To nRecips - 1) As MapiRecip
ReDim Files(0 To nFiles - 1) As MapiFile
rc& = BMAPIGetReadMail(Info&, Message, Recips(), Files(), Orig)
ReDim FilesOut(0 To nFiles - 1) As MapiFile
ReDim RecipsOut(0 To nRecips - 1) As MapiRecip
For i = 0 To nRecips - 1
Ignore& = CopyRecipient(Recips(i), RecipsOut(i))
Next i
For i = 0 To nFiles - 1
Ignore& = CopyFiles(Files(i), FilesOut(i))
Next i
End If
MAPIReadMail = rc&
End Function
Function SendMailTest(usuario As String, modi As String)
Dim oMsg As MAPIMessage
Dim oRecipients(1) As MapiRecip
Dim oAttachments(0) As MapiFile
Dim lSession As Long
Dim lResult As Long
' Login
lResult = MAPILogon(0, usuario, "", MAPI_LOGON_UI + MAPI_NEW_SESSION, 0, lSession)
If lResult <> 0 Then
Exit Function
End If
' estructura de mensaje saliente
With oMsg
.Reserved = 0
.NoteText = "cuerpo del mensaje"
.FileCount = 0 'sin adjunto
.RecipCount = 1 'solo un recipiente
.Subject = Date & " - " & Time & " Pedrito clavo un clabito"
End With
' estructura salida
With oRecipients(0)
.Name = "direccion@gmail.com"
.RecipClass = MAPI_TO
.Reserved = 0
End With
lResult = MAPIResolveName(lSession, 0, oRecipients(0).Name, 0, 0, oRecipients(0))
If lResult <> 0 Then
Exit Function
End If
' enviamos l mensaje
lResult = MAPISendMail(0, 0, oMsg, oRecipients, oAttachments, 0, 0&)
If lResult = 0 Then
a = 1
Else
a = 2
End If
'desconectamos
lResult = MAPILogoff(lSession, 0, 0, 0)
If lResult <> 0 Then
a = 3
End If
End Function