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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
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???
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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!
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?
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 ...
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
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....
GefflCommented:
Which e-mail client do you use now?
chewhoungCommented:
If you're using Exchange, go to control panel->Mail->Show Profile->Add to add a new profile.
chewhoungCommented:
If you're using Exchange, go to control panel->Mail->Show Profile->Add to add a new profile.
chewhoungCommented:
Sorry For Reposting.
kulikuliAuthor Commented:
I'm still using Pegasus.
GefflCommented:
I´m sorry, but I think, that my sample code won´t work with pegasus!
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.