News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Using the MAPI

Started by Lightman, December 29, 2008, 04:35:43 PM

Previous topic - Next topic

Lightman

Hi Everybody,

I have been trying to write some code that uses the MAPI to access email.  My aim is to check a pre-existing mailbox for new mail.  First of all, I understand that I must connect to the mailbox and establish a session, this session is then used for sending and reading mail.  I am trying to use a MAPI function MAPILogon that lives in the MAPI32.DLL.

I load in the DLL file and get an address from for the function I am wanting to use. Then I setup the MAPI call like so...


; Log onto the mail server, the address of the external procedure is contained in hmLogon, first push the
; parameters onto the stack...

push hWnd ; UIParam, either 0 or the handle of the controling windows
push offset ProfileName ; lpszProfileName
push offset MailPassword ; lpszPassword
push 0 ; flFlags
push 0 ; ulReserved
push offset hMailSession ; lplhSession
call hmLogon

.if(eax != SUCCESS_SUCCESS)
  invoke SendMessage, hConsole, WM_SETTEXT, 0, addr MailLogErr
.else
  invoke SendMessage, hConsole, WM_SETTEXT, 0, addr MailLogWin
.endif


The code compiles and runs, but will not establish a connection and I am stumped as to why.  It's a RadASM project, so I have atteched the whole project if anyone wants a look.


Thanks,

Lightman


[attachment deleted by admin]


Farabi

Lightman:
Dont forget to adjust the ESP after calling the function.

Quote
push hWnd   ; UIParam, either 0 or the handle of the controling windows
push offset ProfileName ; lpszProfileName
push offset MailPassword ; lpszPassword
push 0 ; flFlags
push 0 ; ulReserved
push offset hMailSession ; lplhSession
call hmLogon
add esp,6*4
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Tedd

Quote from: Farabi on December 30, 2008, 01:07:53 AM
Lightman:
Dont forget to adjust the ESP after calling the function.
No.
That's necessary for C functions - these are not (the function itself will adjust the stack on return.)
No snowflake in an avalanche feels responsible.

Lightman

Hi Everyone,

Thanks for the replies. Going though the postings, I notice that nobody uses the MAPILogon function anywow; they just go right ahead and send some mail.  In an effort to understand what is going on, I created my own program simply to send mail and as you might guess, I can't get that to work either...

The code compiles and runs, but when I click my send button, I get a failure.  I checked with the value returned in eax but could not match it to any error message. Here is a rough snipet.  The actual RadASM project is attached....


; -- Load my DLL Procedures --
invoke LoadLibrary, offset MapiDLLStr ; load from external DLL
mov hMAPI, eax ; handle of the DLL
invoke GetProcAddress, hMAPI, offset MapiSndStr ; load the adress of the external procedure
mov dll_MAILSEND, eax ; save address for later calling

invoke RtlZeroMemory, addr MMessage, sizeof MMessage ; create a memory structure for the message
invoke RtlZeroMemory, addr MRecipnt, sizeof MRecipnt ; cteate a memory structure for the recipient

; Put some value into the message array.
mov MMessage.lpszSubject, offset mSubject ; Subject
mov MMessage.lpszNoteText, offset MapiBody ; Main e-mail text
mov MMessage.lpRecips, offset MRecipnt ; pointer to the structure for recipients

; Put some values into the recipint array
mov MRecipnt.lpszAddress, offset MapiTo ; a vaild email address
mov MRecipnt.lpszName, offset MapiName ; 'from' user name
mov MRecipnt.ulRecipClass, MAPI_TO ; what class the recipient is, in this case a standard


.elseif eax==WM_COMMAND
mov eax,wParam
and eax,0FFFFh
.if eax==IDC_SEND
; call for the DLL procedure...

push NULL ; Reserved
push MAPI_DIALOG or MAPI_LOGON_UI ; ulFlags
push offset MMessage ; MAPI Strucrture of email message.
push NULL ; ulParam
push NULL ; MAPI Session
call dll_MAILSEND ; Call for external procedure


.if (eax != SUCCESS_SUCCESS)
invoke MessageBox, hWnd, addr MailErr, addr AppName, MB_OK
.endif

push eax ; save the content of eax
invoke FreeLibrary, hMAPI ; free off the library that I don't need
pop eax ; recover eax



I had better note that I am very much a beginner, having just completed Icze's tutorials so it maybe some silly coding error...

Regards,

Lightman

[attachment deleted by admin]

ragdog

hi

http://www.codeproject.com/KB/IP/cmapi.aspx
http://www.asmcommunity.net/board/index.php?topic=26040.0

I hope it can help you

Why use you Mapi for send a Mail?

It gives good Mail sender here on board

Greets,