Solved

MAPISendMessage

Posted on 1998-10-19
15
274 Views
Last Modified: 2008-03-10
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.
0
Comment
Question by:kulikuli
  • 7
  • 5
  • 3
15 Comments
 
LVL 1

Accepted Solution

by:
Geffl earned 50 total points
Comment Utility
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
 
LVL 5

Author Comment

by:kulikuli
Comment Utility
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
 
LVL 5

Author Comment

by:kulikuli
Comment Utility
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
 
LVL 1

Expert Comment

by:Geffl
Comment Utility
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
 
LVL 5

Author Comment

by:kulikuli
Comment Utility
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
 
LVL 1

Expert Comment

by:Geffl
Comment Utility
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
 
LVL 5

Author Comment

by:kulikuli
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 5

Author Comment

by:kulikuli
Comment Utility
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
 
LVL 1

Expert Comment

by:Geffl
Comment Utility
Which e-mail client do you use now?
0
 
LVL 5

Expert Comment

by:chewhoung
Comment Utility
If you're using Exchange, go to control panel->Mail->Show Profile->Add to add a new profile.
0
 
LVL 5

Expert Comment

by:chewhoung
Comment Utility
If you're using Exchange, go to control panel->Mail->Show Profile->Add to add a new profile.
0
 
LVL 5

Expert Comment

by:chewhoung
Comment Utility
Sorry For Reposting.
0
 
LVL 5

Author Comment

by:kulikuli
Comment Utility
I'm still using Pegasus.
0
 
LVL 1

Expert Comment

by:Geffl
Comment Utility
I´m sorry, but I think, that my sample code won´t work with pegasus!
0
 
LVL 5

Author Comment

by:kulikuli
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now