?
Solved

Using MAPI to get email from Exchange

Posted on 2001-08-03
6
Medium Priority
?
339 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 150 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

800 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