MAPISendMessage

I'm trying to use the MAPISendMessage function to send a plain text message.
However, I only got the function, the constants and some arguments. I don't know how to use them.

I'd like to have an example. Most important: I don't want any control to be involved. Just call a MAPI function to send a text-string message. Can anyone please help me?
If worth the answer I will increase the points, of course.
LVL 5
kulikuliAsked:
Who is Participating?
 
GefflCommented:
Create a new module and paste the following code in it:

Public Declare Function MAPILogon Lib "MAPI32.DLL" (ByVal UIParam&, ByVal User$, ByVal Password$, ByVal Flags&, ByVal Reserved&, Session&) As Long
Public 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
Public Declare Function MAPILogoff Lib "MAPI32.DLL" (ByVal Session&, ByVal UIParam&, ByVal Flags&, ByVal Reserved&) As Long
Public Declare Function MAPIResolveName Lib "MAPI32.DLL" Alias "BMAPIResolveName" (ByVal Session&, ByVal UIParam&, ByVal UserName$, ByVal Flags&, ByVal Reserved&, Recipient As MapiRecip) As Long
Public Declare Function MAPIFindNext Lib "MAPI32.DLL" Alias "BMAPIFindNext" (ByVal Session&, ByVal UIParam&, MsgType$, SeedMsgID$, ByVal Flag&, ByVal Reserved&, MsgID$) As Long



Global MAPISess As Long
Global MAPISessOK As Boolean

Public Const MAPI_DIALOG = &H8
Public Const MAPI_NEW_SESSION = &H2
Public Const MAPI_LOGON_UI = &H1
Public Const MAPI_UNREAD_ONLY = &H20
Public Const MAPI_E_NO_MESSAGES = 16

Public Type MapiFile
    Reserved As Long
    Flags As Long
    Position As Long
    PathName As String
    FileName As String
    FileType As String
End Type

Public 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

Public Type MapiRecip
    Reserved As Long
    RecipClass As Long
    Name As String
    Address As String
    EIDSize As Long
    EntryID As String
End Type

Public Function OpenSession()
    Call MAPIModule.MAPILogon(0, "<ProfileName>", "", MAPI_LOGON_UI, 0, MAPISess)
    If MAPISess > 0 Then
        MAPISessOK = True
    Else
        MAPISessOK = False
    End If
End Function
Public Function SendMail(Text$)
    If MAPISessOK = True Then
        Dim MAPIEmpf(0) As MapiRecip
        Dim MAPIDatei(0) As MapiFile
        Dim MAPINachricht As MAPIMessage

        MAPINachricht.Subject = "<Subject of text>"
        MAPINachricht.NoteText = "<Text>"
               
        Call MAPIModule.MAPIResolveName(MAPISess, 0, "<To>", MAPI_DIALOG, 0, MAPIEmpf(0))
        MAPINachricht.RecipCount = 1
        Call MAPIModule.MAPISendMail(MAPISess, 0, MAPINachricht, MAPIEmpf, MAPIDatei, 0, 0)
    End If
End Function
Public Function CloseSession()
    If MAPISessOK = True Then
        ret& = MAPIModule.MAPILogoff(MAPISess, 0, 0, 0)
    End If
End Function

Use these functions:
    MAPIModule.OpenSession
    MAPIModule.SendMail ("Text")
    MAPIModule.CloseSession
In MapiModule.OpenSession you have to correct the profile name which is stored locally on your workstation.
I hope this can help you and I´ve tested it only with Exchange 5 and Winnt WS 4 SP3 ...

kind regards
0
 
kulikuliAuthor Commented:
Geffl, Thank you very much!!! I've been searching for weeks for something like this! I'll get back to you as soon as I got the results from my implementing it. Just to let you know: I'm using Pegasus Mail for Win32.
0
 
kulikuliAuthor Commented:
What I in fact really am trying to do is send an email without even using a mailapplication like Pegasus or Outlook. Is this not possible at all???
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
GefflCommented:
In such a case you should try to use a command-line SMTP mail program (such as blat). This solution has a lot advantages:
You need no client application installed, because the mapi.dll will be installed with the client.
You can attach files easily.
There´s no dependency on the client application. I don´t know which differences the mapi.dll of Pegasus has compared with Outlook. If you can´t find blat.exe, post it here and I´ll help!
0
 
kulikuliAuthor Commented:
I've been looking for Blat and I found it. It seems to have some nice capabilities for use in scripts for example. However, my objective is to have an email sent by my application. I won't bother about including another dll to call some functions on, but Blat seems to edit the registry. This is something I'd like to avoid. But I'd like to thank you once more for pointing it out to me. Since the sourcecode is all availlable I might try to rewrite Blat to my own specifications. I guess, without a program like Blat or mailapplication there is no possibility to email? There is no standard functionality in Windows avaliable? Like some Telnet dll or whatever?
0
 
GefflCommented:
No. There are no standard-functions in Windows, because each e-mail client provides a different API with different functions. So the best way for you to be independent, is using standard SMTP communication. You can program your own functions (Winsocket connection, open port 25, ...) or you can use already written utilities ...
0
 
kulikuliAuthor Commented:
Thank you very much for all your comments. I am really learning (and losing some illusions) on how to provide email capabilities. I'll get back to you after testing your function.
Best regards,

kulikuli
0
 
kulikuliAuthor Commented:
I am experiencing a problem when testing your code. I suspect it has to be something to do with the profile. I use windows 95 and I don't know what profile I have to give in. This is probably causing MS Access to crash, because each time I run the procedure it crashes....
0
 
GefflCommented:
Which e-mail client do you use now?
0
 
chewhoungCommented:
If you're using Exchange, go to control panel->Mail->Show Profile->Add to add a new profile.
0
 
chewhoungCommented:
If you're using Exchange, go to control panel->Mail->Show Profile->Add to add a new profile.
0
 
chewhoungCommented:
Sorry For Reposting.
0
 
kulikuliAuthor Commented:
I'm still using Pegasus.
0
 
GefflCommented:
I´m sorry, but I think, that my sample code won´t work with pegasus!
0
 
kulikuliAuthor Commented:
Well, I guess I have to post this question once more...
However, I feel I have to reward you for your efforts and for the hint on Blat and inspiration... so thank you very much for that.
Best regards,

kulikuli
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.