V
VT @ home
The environment.
Five clients with Win Xp Pro, linked to a LAN with a primary domain Win
Server 2008 standard.
Two of the clients have Outlook 2003.
Three of the clients have Outlook 2007.
Every user has an unique account defined on the server and can make
login on every pc but can make login only on one pc at any time.
The need.
One of the users needs to manage the incoming and the outgoing e-mail of
three different POP3 accounts.
The user needs to do that using any of the pcs.
My solution.
On every pc I created an Outlook profile and configured the three
different e-mail accounts.
Then I linked to the above mentioned Outlook profile three different pst
files (one for each e-mail account).
The pst files reside in a shared folder of the server with R/W permissions.
At the end I defined several rules in the Outlook profile to move the
incoming and outgoing mail in the corresponding pst file, choosen using
the sender address (for outgoing mail) or the recipient address (for
incoming e-mail).
This solution have never worked fine and at the end it stopped working
because, as I could verify last week, the rules disappeared !
The user says that she didn't do anything and I can trust her.
So I thought that VBA would be safer and I wrote the following code:
Option Explicit
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Call Smista("Out")
End Sub
Private Sub Application_NewMail()
Call Smista("In")
End Sub
Public Sub Smista(pTipo As String)
On Error GoTo Err
Dim objOlApp As Outlook.Application
Dim objSourceNameSpace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder, objMsg As MailItem
Dim objDestNameSpace As Outlook.NameSpace
Dim objDestFolder As Outlook.MAPIFolder, objNewMsg As MailItem
Dim i As Long
' Crea un oggetto di tipo Outlook
Set objOlApp = CreateObject("Outlook.Application")
' Recupera il namespace di tipo MAPI
Set objSourceNameSpace = objOlApp.GetNamespace("MAPI")
If pTipo = "In" Then
' Recupera la cartella della posta in arrivo
Set objSourceFolder =
objSourceNameSpace.GetDefaultFolder(olFolderInbox)
End If
If pTipo = "Out" Then
' Recupera la cartella della posta inviata
Set objSourceFolder =
objSourceNameSpace.GetDefaultFolder(olFolderSentMail)
End If
' Recupera il primo messaggio nella cartella sorgente
Set objMsg = objSourceFolder.Items.GetFirst
' Cicla sui messaggi nella cartella sorgente
For i = 1 To objSourceFolder.Items.Count
Set objMsg = objSourceFolder.Items.Item(i)
If pTipo = "In" Then
' Imposta la cartella di destinazione
If InStr(1, LCase(objMsg.Recipients), "becucci") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.
Becucci").Folders("Posta in arrivo")
End If
If InStr(1, LCase(objMsg.Recipients), "simone") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.
Simone").Folders("Posta in arrivo")
End If
If InStr(1, LCase(objMsg.Recipients), "minigrilli") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.ssa
Minigrilli").Folders("Posta in arrivo")
End If
End If
If pTipo = "Out" Then
' Imposta la cartella di destinazione
If InStr(1, LCase(objMsg.SenderEmailAddress), "becucci") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.
Becucci").Folders("Posta inviata")
End If
If InStr(1, LCase(objMsg.SenderEmailAddress), "simone") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.
Simone").Folders("Posta inviata")
End If
If InStr(1, LCase(objMsg.SenderEmailAddress), "minigrilli") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.ssa
Minigrilli").Folders("Posta inviata")
End If
End If
' Crea una copia del messaggio
Set objNewMsg = objMsg.Copy
' Sposta la copia del messaggio nella cartella di destinazione
objNewMsg.Move objDestFolder
objMsg.Delete
Next i
Set objMsg = Nothing
Set objNewMsg = Nothing
Set objOlApp = Nothing
Set objSourceNameSpace = Nothing
Set objSourceFolder = Nothing
Set objDestFolder = Nothing
Exit Sub
Err:
If Err.Number <> 0 Then
Debug.Print Err.Description & vbCrLf & i & " - Data: " &
objMsg.ReceivedTime
Resume Next
End If
End Sub
This code works only on the clients with Outlook 2003; in Outlook 2007
it's not executed.
I set a breakpoint on Call Smista("Out") then I sent a message, but the
code didn't stop; so I think it never started !
The same happened (better: nothing happened !) when I received a message.
My questions are:
- why does the code work only in Outlook 2003 ?
- is the solution correct and, if the answer is negative, what else
could I try ?
Please don't suggest the purchase of Exchange: is too expensive for my
customer.
Thanks in advance to everybody who will answer.
Five clients with Win Xp Pro, linked to a LAN with a primary domain Win
Server 2008 standard.
Two of the clients have Outlook 2003.
Three of the clients have Outlook 2007.
Every user has an unique account defined on the server and can make
login on every pc but can make login only on one pc at any time.
The need.
One of the users needs to manage the incoming and the outgoing e-mail of
three different POP3 accounts.
The user needs to do that using any of the pcs.
My solution.
On every pc I created an Outlook profile and configured the three
different e-mail accounts.
Then I linked to the above mentioned Outlook profile three different pst
files (one for each e-mail account).
The pst files reside in a shared folder of the server with R/W permissions.
At the end I defined several rules in the Outlook profile to move the
incoming and outgoing mail in the corresponding pst file, choosen using
the sender address (for outgoing mail) or the recipient address (for
incoming e-mail).
This solution have never worked fine and at the end it stopped working
because, as I could verify last week, the rules disappeared !
The user says that she didn't do anything and I can trust her.
So I thought that VBA would be safer and I wrote the following code:
Option Explicit
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Call Smista("Out")
End Sub
Private Sub Application_NewMail()
Call Smista("In")
End Sub
Public Sub Smista(pTipo As String)
On Error GoTo Err
Dim objOlApp As Outlook.Application
Dim objSourceNameSpace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder, objMsg As MailItem
Dim objDestNameSpace As Outlook.NameSpace
Dim objDestFolder As Outlook.MAPIFolder, objNewMsg As MailItem
Dim i As Long
' Crea un oggetto di tipo Outlook
Set objOlApp = CreateObject("Outlook.Application")
' Recupera il namespace di tipo MAPI
Set objSourceNameSpace = objOlApp.GetNamespace("MAPI")
If pTipo = "In" Then
' Recupera la cartella della posta in arrivo
Set objSourceFolder =
objSourceNameSpace.GetDefaultFolder(olFolderInbox)
End If
If pTipo = "Out" Then
' Recupera la cartella della posta inviata
Set objSourceFolder =
objSourceNameSpace.GetDefaultFolder(olFolderSentMail)
End If
' Recupera il primo messaggio nella cartella sorgente
Set objMsg = objSourceFolder.Items.GetFirst
' Cicla sui messaggi nella cartella sorgente
For i = 1 To objSourceFolder.Items.Count
Set objMsg = objSourceFolder.Items.Item(i)
If pTipo = "In" Then
' Imposta la cartella di destinazione
If InStr(1, LCase(objMsg.Recipients), "becucci") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.
Becucci").Folders("Posta in arrivo")
End If
If InStr(1, LCase(objMsg.Recipients), "simone") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.
Simone").Folders("Posta in arrivo")
End If
If InStr(1, LCase(objMsg.Recipients), "minigrilli") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.ssa
Minigrilli").Folders("Posta in arrivo")
End If
End If
If pTipo = "Out" Then
' Imposta la cartella di destinazione
If InStr(1, LCase(objMsg.SenderEmailAddress), "becucci") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.
Becucci").Folders("Posta inviata")
End If
If InStr(1, LCase(objMsg.SenderEmailAddress), "simone") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.
Simone").Folders("Posta inviata")
End If
If InStr(1, LCase(objMsg.SenderEmailAddress), "minigrilli") > 0 Then
Set objDestFolder = objSourceNameSpace.Folders("Dr.ssa
Minigrilli").Folders("Posta inviata")
End If
End If
' Crea una copia del messaggio
Set objNewMsg = objMsg.Copy
' Sposta la copia del messaggio nella cartella di destinazione
objNewMsg.Move objDestFolder
objMsg.Delete
Next i
Set objMsg = Nothing
Set objNewMsg = Nothing
Set objOlApp = Nothing
Set objSourceNameSpace = Nothing
Set objSourceFolder = Nothing
Set objDestFolder = Nothing
Exit Sub
Err:
If Err.Number <> 0 Then
Debug.Print Err.Description & vbCrLf & i & " - Data: " &
objMsg.ReceivedTime
Resume Next
End If
End Sub
This code works only on the clients with Outlook 2003; in Outlook 2007
it's not executed.
I set a breakpoint on Call Smista("Out") then I sent a message, but the
code didn't stop; so I think it never started !
The same happened (better: nothing happened !) when I received a message.
My questions are:
- why does the code work only in Outlook 2003 ?
- is the solution correct and, if the answer is negative, what else
could I try ?
Please don't suggest the purchase of Exchange: is too expensive for my
customer.
Thanks in advance to everybody who will answer.