Solved

Mapi Fowarding

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

790 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