Solved

Mapi Fowarding

Posted on 2000-04-07
1
241 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

740 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