Solved

Using MAPI to get email from Exchange

Posted on 2001-08-03
6
333 Views
Last Modified: 2012-08-13
I want code that will use MAPI to get email from Microsoft Exchange (including attachments).
0
Comment
Question by:alaplume
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6349939
You should have a sample on your computer that does exactly what you're asking

Mine is found here
D:\Program Files\DevStudio\VB\samples\CompToop\VBMail
0
 
LVL 3

Accepted Solution

by:
andysalih earned 50 total points
ID: 6349988
this shows how to use MAPI control with VB


Public Function SendMAPIMail( _
    MsgTo As String, _
    Optional CC As String = "", _
    Optional Subject As String = "", _
    Optional Body As String = "", _
    Optional Att As String = "") _
    As Boolean
    'Code by Conrad
    'email cbrits@monotix.co.za
   
    '---------------------------------------
    '     --------
    '** PLEASE NOTE!! **
    'You need a form with both
    'controls (MapiMessages and MapiSession)
    '     on it
    '
    'Do the following:
    '-----------------
    '1.Add a form, and name it frmMail.
    '2.Go to Components...(Project menu) and
    '     find
    ' Microsoft MAPI Controls.
    '3.Check it, and click OK. There will no
    '     w
    ' be two
    ' new controls on your Control Tab.
    '4.Add the two new controls to your form
    '     .
    '
    '---------------------------------------
    '     --------
    On Error GoTo ErrHndl
   
   
    Dim MAPISes As MAPISession
    Dim MAPIMsgs As MAPIMessages
   
   
    Screen.MousePointer = 11
   
    'set the objects to the controls of the


    '     form
        Set MAPISes = frmMail.MAPISession1
        Set MAPIMsgs = frmMail.MAPIMessages1
       
        'download new mail = false
        MAPISes.DownLoadMail = False
        'show the logon interface for the mail
        'account = true
        MAPISes.LogonUI = True
        'sign on to selected account
        MAPISes.SignOn
       


        DoEvents
           
            'check if logon was successful


            If MAPISes.SessionID = 0 Then
                SendMAPIMail = False
                MsgBox "Error on login to MAPI", _
                vbCritical, "MAPI"
                Exit Function
            End If
           
            'set the session IDs the same on both ob
            '     jects
            MAPIMsgs.SessionID = MAPISes.SessionID
           
            'Set the MSgIndex to -1, this needs to b
            '     e
            'done for the Compose event to work
            MAPIMsgs.MsgIndex = -1
            'compose a new message
            MAPIMsgs.Compose
           
            'don't show the resolve address interfac
            '     e
            MAPIMsgs.AddressResolveUI = False
           
           
            'set the recipient
            MAPIMsgs.RecipIndex = 0
            MAPIMsgs.RecipType = mapToList
            MAPIMsgs.RecipAddress = MsgTo
            'resolve the recipient's email addresses
            '    
            MAPIMsgs.ResolveName
           
            'set the CC recipient
            MAPIMsgs.RecipIndex = 1
            MAPIMsgs.RecipType = mapCcList
            MAPIMsgs.RecipAddress = CC
            'resolve the recipient's email addresses
            '    
            MAPIMsgs.ResolveName
           
            'set the subject
            MAPIMsgs.MsgSubject = Subject
           
            'set the Message/Body/NoteText
            MAPIMsgs.MsgNoteText = Body
           


            If Att <> "" Then
                'set an attachment
                MAPIMsgs.AttachmentPathName = Att
            End If
            'send the message
            MAPIMsgs.Send
           
            'close the current session
            MAPISes.SignOff
           
            'clear objects
            Set MAPIMsgs = Nothing
            Set MAPISes = Nothing
           
            SendMAPIMail = True
           
            Screen.MousePointer = 0
            Exit Function
            ErrHndl:
            Set MAPIMsgs = Nothing
            Set MAPISes = Nothing
           
            Screen.MousePointer = 0
            MsgBox "Error [" & Err & "] " & Error, vbCritical, "MAPI"
            Screen.MousePointer = 11
           
            On Error Resume Next
            frmMail.MAPISession1.SignOff
            SendMAPIMail = False
           
            Screen.MousePointer = 0
        End Function


cheers
Andy
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6755532
Please update and finalize this and all your open questions here.  It helps you achieve your goal if you remain active in all your open questions and provide feedback on progress made to the experts who step in to help you.

Please check the HELP DESK link on the left, which contains the Guidelines for this site, Member Agreement and information on the Question/Answer process.

Thanks,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6758077
alaplume--->  You've asked 9 questions, only finalized two of them.  Please remain active in all your open questions, provide feedback to the experts who step in to help you if more is needed, and award those who have helped you in them.  

If you need help from Community Support, please post a zero point question in the Community Support topic area, include the link to the question involved with your request.

The HELP DESK link n the left offers guidance regarding this site, including the Question/Answer process, Guidelines and Member Agreement.

Monitoring for seven days for updates/completion of your old, open questions.  If still unresolved, will contact Administration for further handling.

Thanks for your responsiveness.

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

688 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