Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MAPI, CDO or Winsock 1

Status
Not open for further replies.

wASP

Programmer
Jun 28, 2001
23
0
0
ZA
Hi

Have to write an exe that will be deployed to a large userbase. The exe must check the local machines email inbox for a specific attachment on a daily basis and save this file to a spesified location.

The probelm is not with writing the app, but rather using the right technology ie. MAPI, CDO or WINSOCK.

Our current solution uses MAPI, but we have some troubles when the local machine has Outlook 2003 installed.

Any ideas as to what technology would be best, and would be compatable with any email client ?



>:):O> wASP >:):O>
 
CDO would only work with Outlook or Outlook Express, WINSOCK would be used in Conjunction with MAPI. We use MAPI for our email programs here. have never had an issue.

Casper

There is room for all of gods creatures, "Right Beside the Mashed Potatoes".
 
Hi Casper

Tnx for the reply. MAPI works perfect, except when trying to connect to a local Outlook 2003 client.

The problem with CDO however would be limitation on operating systems.

Our solution would need to extend to any Outlook version as well as any windows operating system version.

Mapi would be great, if i could get it working with outlook 2003....

>:):O> wASP >:):O>
 
I would work on the problems that you have with Outlook 2003. Rather than trying to find something else.

Casper

There is room for all of gods creatures, "Right Beside the Mashed Potatoes".
 
getting a "function not supported" error when running the below code on a machine with outlook 2003 installed.

=====================================================

Option Explicit
Public m_bSignedOn As Boolean
Private Sub Form_Load()

Call SignOn
If m_bSignedOn Then
CheckForMail
End If
'SignOFF
Unload Me
End Sub
Private Function SignOFF() As Boolean

If m_bSignedOn Then
MAPSession.SignOFF
End If

End Function
Private Function SignOn() As Boolean
SignOn = True

If m_bSignedOn Then
Exit Function
End If

On Error GoTo eh

MAPSession.SignOn
MAPMessage.SessionID = MAPSession.SessionID
MAPMessage.Compose

m_bSignedOn = True

Exit Function

eh:
Select Case Err.Number
Case 32003 ' user cancelled
Case Else
MsgBox "Could not sign on to the specified mail account.", vbExclamation, "Sign On"
End Select
SignOn = False
End Function
Private Sub CheckForMail()
Dim i As Integer
Dim sSubject As String
Dim sAttachmentName As String

MAPMessage.FetchUnreadOnly = True
MAPMessage.Fetch

If MAPMessage.MsgCount Then

For i = 0 To MAPMessage.MsgCount - 1
MAPMessage.MsgIndex = i
sSubject = UCase(MAPMessage.MsgSubject)

If sSubject = "SUBJECT HERE" Then

If MAPMessage.AttachmentCount Or MAPMessage.AttachmentPathName > " " Then
MAPMessage.AttachmentIndex = 0
sAttachmentName = MAPMessage.AttachmentPathName
FileCopy MAPMessage.AttachmentPathName, App.Path & "\ratesupd.dat"
Exit Sub
End If
End If
Next
End If
End Sub


Private Sub Form_Unload(Cancel As Integer)
SignOFF
End Sub

=====================================================

any ideas ?

>:):O> wASP >:):O>
 
Do you know on which function or line it dies?

What you can do is put line numbers in and then have proper error handling routines... Here is a simple way of doing this...

Code:
Option Explicit
Public m_bSignedOn As Boolean
[COLOR=blue]Const m_Source As String = "MyProject"[/color]

Private Sub Form_Load()
[COLOR=blue]On Error GoTo HandleError
    Const myName As String = m_Source & ".Load"[/color]
[COLOR=blue]100:[/color]
   Call SignOn
[COLOR=blue]200:[/color]
   If m_bSignedOn Then
      CheckForMail
   End If
[COLOR=blue]300:[/color]
   'SignOFF
   Unload Me
[COLOR=blue]
Exit Sub
HandleError:
    Call GlobalErr(m_strSource & myName & ": ERR#" & str(Err) & ", Desc:" & Err.Description & ", Line:" & Erl)[/color]
End Sub

Private Function SignOFF() As Boolean
[COLOR=blue]On Error GoTo HandleError
    Const myName As String = m_Source & ".SignOFF"[/color]
[COLOR=blue]100:[/color]
  If m_bSignedOn Then
[COLOR=blue]200:[/color]
    MAPSession.SignOFF
  End If
[COLOR=blue]
Exit Function
HandleError:
    Call GlobalErr(m_strSource & myName & ": ERR#" & str(Err) & ", Desc:" & Err.Description & ", Line:" & Erl)[/color]
End Function

Private Function SignOn() As Boolean
[COLOR=blue]On Error GoTo HandleError
    Const myName As String = m_Source & ".SignOn"[/color]
   SignOn = True

[COLOR=blue]100:[/color]
   If m_bSignedOn Then
      Exit Function
   End If
   
[COLOR=blue]100:[/color]
   On Error GoTo eh
   
   MAPSession.SignOn
   MAPMessage.SessionID = MAPSession.SessionID
   MAPMessage.Compose
   
[COLOR=blue]100:[/color]
   m_bSignedOn = True
   
   Exit Function
   
eh:
   Select Case Err.Number
      Case 32003     ' user cancelled
      Case Else
         MsgBox "Could not sign on to the specified mail account.", vbExclamation, "Sign On"
   End Select
   SignOn = False
[COLOR=blue]
Exit Function
HandleError:
    Call GlobalErr(m_strSource & myName & ": ERR#" & str(Err) & ", Desc:" & Err.Description & ", Line:" & Erl)[/color]
End Function

Private Sub CheckForMail()
[COLOR=blue]On Error GoTo HandleError
    Const myName As String = m_Source & ".CheckForMail"[/color]
    Dim i As Integer
    Dim sSubject As String
    Dim sAttachmentName As String
    
    MAPMessage.FetchUnreadOnly = True
    MAPMessage.Fetch

    If MAPMessage.MsgCount Then
      
        For i = 0 To MAPMessage.MsgCount - 1
            MAPMessage.MsgIndex = i
            sSubject = UCase(MAPMessage.MsgSubject)
         
            If sSubject = "SUBJECT HERE" Then
       
                If MAPMessage.AttachmentCount Or MAPMessage.AttachmentPathName > " " Then
                    MAPMessage.AttachmentIndex = 0
                    sAttachmentName = MAPMessage.AttachmentPathName
                    FileCopy MAPMessage.AttachmentPathName, App.Path & "\ratesupd.dat"
                    Exit Sub
                End If
            End If
        Next
    End If
[COLOR=blue]
Exit Sub
HandleError:
    Call GlobalErr(m_strSource & myName & ": ERR#" & str(Err) & ", Desc:" & Err.Description & ", Line:" & Erl)[/color]
End Sub

Private Sub Form_Unload(Cancel As Integer)
[COLOR=blue]On Error GoTo HandleError
    Const myName As String = m_Source & ".Form_Unload"[/color]
   SignOFF
[COLOR=blue]
Exit Sub
HandleError:
    Call GlobalErr(m_strSource & myName & ": ERR#" & str(Err) & ", Desc:" & Err.Description & ", Line:" & Erl)[/color]
End Sub

You have to add more line numbering and create a function called GlobalErr that logs the errors to a file. But you get the idea I hope...

What will happen is you will creat an error log file that will ahve entries that look like...

MyProject.CheckFormail: ERR#80042, Desc:Some Error Happened, Line:200


Casper

There is room for all of gods creatures, "Right Beside the Mashed Potatoes".
 
There is more on error handling in my FAQ faq222-1694

Casper

There is room for all of gods creatures, "Right Beside the Mashed Potatoes".
 
Hi Casper

Just found the problem with using vb6 to connect to outlook 2003 using MAPI. It seems Outlook 2003 has built in security which sees any external application trying to connect to it as malicious code, and usually brings up a warning to allow or deny this access. When running the app using MAPI, outlook automatically blocks this request whitout warning displaying a 32026 on setting the message index.

Will have to start playing with now..... gonna get interesting i thinks. thx for all the help.


>:):O> wASP >:):O>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top