Solved

Mapi Fowarding

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

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
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…

729 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