Solved

Mapi Fowarding

Posted on 2000-04-07
1
237 Views
Last Modified: 2013-12-25
I am trying to creat a small app that will Loop through my inbox in outlook and foward all messages to another address.  This is what I'm working with -
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
                                        (ByVal lpBuffer As String, nSize As Long) As Long

Private Sub main()
    Dim sUserName As String * 255
    Dim sRetName As String
    Dim lRetLen As Long
    Dim iLoc As Integer
    Dim sActUser As String
    Dim lRecipNum As Long
    Dim lLen As Long
    Dim lMsgCtr As Long
   
    Dim Mail1 As Object
    Dim Msg1 As Object
    Set Mail1 = New MAPISession
    Set Msg1 = New MAPIMessages
   
   
    On Error GoTo Eh
    If Mail1.SessionID <> 0 Then
        Exit Sub
    End If
       
    With Mail1
        'get user profile info
        sUserName = String(254, " ")
        sUserName = sUserName & vbNullChar
        lRetLen = GetUserName(sUserName, Len(sUserName))
        iLoc = InStr(sUserName, " ")
        sUserName = Left(sUserName, iLoc - 2)
        sActUser = Trim(sUserName)

        .NewSession = False
        .LogonUI = False
        .UserName = sActUser
     
        .SignOn
        Msg1.SessionID = .SessionID
        Msg1.Fetch
        For lMsgCtr = 0 To Msg1.MsgCount - 1
            Msg1.MsgIndex = lMsgCtr
            Msg1.Forward
            MsgBox Msg1.MsgType
            lRecipNum = Msg1.RecipCount
            Msg1.RecipIndex = lRecipNum
            Msg1.RecipType = 1
            Msg1.RecipAddress = "dean.pelosa@empirebcbs.com" 'email address
            Msg1.RecipDisplayName = Msg1.RecipAddress
            Msg1.Send (False)
        Next lMsgCtr

        .SignOff
    End With

On Error GoTo 0
Exit Sub

Eh:
    Select Case Err.Number
        Case Is = 32001
            Resume Next
        Case Is = 32050
            Resume Next
        Case Is = 32003
            On Error GoTo Eh
                    Mail1.UserName = ""
                    Mail1.NewSession = True
                    Mail1.LogonUI = True
                    Mail1.SignOn
            Resume Next
        Case Else
            MsgBox Err.Number & " Description: " & Err.Description
            Resume Next
    End Select
End Sub

- The code does attempt a send, but system always rejects it as undeliverable.  
This is the error I get in outlook for any address I try to foward to:

      'dean.pelosa@empirebcbs.com' on 04/07/2000 10:51 AM
            No transport provider was available for delivery to this recipient.

Anyone have any ideas?
0
Comment
Question by:falkor
1 Comment
 
LVL 20

Accepted Solution

by:
hes earned 100 total points
ID: 2694343
Try changing the following:
Add Const vbExchange As String = "MS Exchange Settings"
Const vbMessageResolveName = 13

..UserName = sActUser   to
..UserName = vbExchange

and just before your send add

Msg1.AddressResolveUI = True

        Msg1.Action = vbMessageResolveName

       
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

746 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

10 Experts available now in Live!

Get 1:1 Help Now