I'm trying to send mail using MAPI in my VB.NET application. Mail message
window opens, but it does't contain recipients and attachments.
My guess is I'm doing something wrong with recip and file arrays. Here is
the code:
Public Structure MapiMessage
Public ulReserved As Integer
Public lpszSubject As String
Public lpszNoteText As String
Public lpszMessageType As String
Public lpszDateReceived As String
Public lpszConversationID As String
Public flFlags As Integer
Public lpOriginator As MapiRecip
Public nRecipCount As Integer
Public lpRecips As Object 'lpMapiRecipDesc
Public nFileCount As Integer
Public lpFiles As Object 'lpMapiFileDesc
End Structure
Public Structure MapiRecip
Public ulReserved As Integer
Public ulRecipClass As Integer
Public lpszName As String
Public lpszAddress As String
Public ulEIDSize As Integer
Public lpEntryID As Object 'lpvoid
End Structure
Public Structure MapiFile
Public ulReserved As Integer
Public flFlags As Integer
Public nPosition As Integer
Public lpszPathName As String
Public lpszFileName As String
Public lpFileType As String 'lpvoid
End Structure
Public Class MAPI
Public Declare Auto Function MapiSendMail Lib "Mapi32.dll" Alias
"MAPISendMail" (ByVal pSession As Integer, ByVal pUIParam As Integer, ByRef
pMsg As MapiMessage, ByVal pFlags As Integer, ByVal pReserved As Integer) As
Integer
Public Sub SendMail(ByVal SendTo As String, ByVal Subject As String,
ByVal Attachment As String)
Dim msg As MapiMessage
Dim recip(1) As MapiRecip
Dim file(1) As MapiFile
recip(0).lpszAddress = "te**@test.com"
recip(0).ulRecipClass = 1
recip(0).lpszName = "Test"
recip(0).ulReserved = 0
recip(0).ulEIDSize = 0
recip(0).lpEntryID = Nothing
file(0).ulReserved = 0
file(0).flFlags = 0
file(0).nPosition = -1
'file(0).lpszPathName = Attachment
'file(0).lpszFileName = Path.GetFileName(Attachment)
file(0).lpszPathName = "C:\temp\test.pdf"
file(0).lpszFileName = "test.pdf"
file(0).lpFileType = Nothing
msg.ulReserved = 0
msg.lpszSubject = "Test subject"
msg.flFlags = 0
msg.lpOriginator = Nothing
msg.lpszConversationID = Nothing
msg.lpszDateReceived = Nothing
msg.lpszMessageType = Nothing
msg.lpszNoteText = "Test message"
msg.lpRecips = recip
msg.nRecipCount = 1
msg.nFileCount = 1
msg.lpFiles = file
Dim MAPIResult As Integer
MAPIResult = MapiSendMail(Nothing, Nothing, msg, 8, Nothing)
End Sub
End Class