Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Using MAPI to get email from Exchange

I want code that will use MAPI to get email from Microsoft Exchange (including attachments).
0
alaplume
Asked:
alaplume
1 Solution
 
Dave_GreeneCommented:
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
 
andysalihCommented:
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
 
MoondancerCommented:
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
 
MoondancerCommented:
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now