Solved

Using MAPI to get email from Exchange

Posted on 2001-08-03
6
297 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
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 16

Expert Comment

by:Richie_Simonetti
ID: 6349962
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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

706 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

15 Experts available now in Live!

Get 1:1 Help Now