OVH Cloud OVH Cloud

Détection Envoi / réception Email

14 réponses
Avatar
Xantia
Bonjour

Je fait communiquer ma base Access avec la messagerie d'Outlook.
J'aimerais en fait "automatiser" mon code pour que dés réception d'un nouvel
Email dans ma boite de réception et/ou dès que j'ai éffectivement envoyé un
E-mail
j'enclenche une action envers ma base Access.

Que est le code VB qui me permet de détecter l'envoie ou la reception de
mes messages ?



merci pour votre aide

@+
Alain

4 réponses

1 2
Avatar
Clive Lumb
Alain,

Pas de problème....

Comme je soupçonnais depuis un moment tu n'utilises pas VB, mais VBA (Ici
c'est le groupe pour VB)....
Ce n'est pas grave, car ce que tu veux faire est tout à fait faisable avec
VBA.

(pour info, VB permet de créer des applications, VBA permet de contrôler les
applications Office etc.. VB est compilé, VBA tourne en interpreté).

Alors en regardant les évenements du modèle Outlook 9 en VBA on ne voit pas
NewMailEx (Ex="extended"), seulement NewMail qui ne rend pas le "item"
reçu - il semblerait que cela n'existe pas avant la version 2003.

Heureusement il y a une solution - l'évenement "ItemAdd" de la boite de
réception.
Ci-après un exemple de chez Microsoft, malheureusement en English....
Bon courage

The following steps create a rule that automatically forwards any mail you
receive outside of regular business hours to another e-mail address, such as
the e-mail address you use at home, or to someone else who works the shift
after yours.


1.. On the Tools menu, point to Macro, and click Visual Basic Editor.


2.. In the Project - Project1 pane, double-click Project1, and
double-click Microsoft Outlook Objects.


3.. Double-click ThisOutlookSession to open a code window.


4.. In the code window, type the following code. Modify the line that
specifies the e-mail address; substitute the e-mail address you want e-mail
forwarded to:



Public WithEvents myOlItems As Outlook.Items


Public Sub Application_Startup()

' Reference the items in the Inbox. Because myOlItems is declared
' "WithEvents" the ItemAdd event will fire below.
Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items

End Sub


Private Sub myOlItems_ItemAdd(ByVal Item As Object)

' If it's currently not between 9:00 A.M. and 5:00 P.M.
If Time() < #9:00:00 AM# Or Time() > #5:00:00 PM# Then

' Check to make sure it is an Outlook mail message, otherwise
' subsequent code will probably fail depending on what type
' of item it is.
If TypeName(Item) = "MailItem" Then

' Forward the item just received
Set myForward = Item.Forward

' Address the message
myForward.Recipients.Add ""

' Send it
myForward.Send

End If

End If

End Sub 5.. On the File menu, click Save VBAProject.otm.


6.. Close the Visual Basic Editor.


7.. Restart Outlook so that the code will run.


NOTE: For more information about how to make sure your code properly handles
various types of items, please see the following article in the Microsoft
Knowledge Base:

Q222482 OL2000: How To Handle Unexpected Items in a Collection
The following considerations should be taken into account if you are
considering implementing a rules solution using Visual Basic for
Applications:

a.. Outlook must be running for the Visual Basic for Application code to
run. This is the same effect as using client-side rules in the Rules Wizard.
If Outlook is not running at the time the message arrives, the rule will not
work.


b.. Your custom rule may conflict with other rules you have set up using
the Rules Wizard. For example, if you are using Microsoft Exchange Server
and create a server-side rule that moves mail from a specific individual to
a specific folder, the mail is moved on the server and never reaches the
Inbox. Therefore, the ItemAdd event does not run since an item is not added
to the Inbox.


c.. The code runs regardless of how an item is added to the Inbox. For
example, if you work late one night and drag a message to your Inbox, the
message is forwarded to the other e-mail account.


d.. Outlook also has a NewMail event, but that event only runs when you
get a new mail notification. If you receive three messages at once, the
event only runs once. You can use the NewMail event to make sure that your
Visual Basic for Applications code only runs when you receive new messages,
but you must add additional logic to the code to search for those messages
that haven't been read before. So unfortunately both events tend to have an
unwanted side effect:


a.. The ItemAdd event makes it easy to act on all of the incoming items,
but it also acts on those items you move to the Inbox yourself.


b.. The NewMail event does not run when you drag items to the Inbox, but
it is more difficult to program a solution to take into account that there
are multiple items in the Inbox that your code must act on.



"Xantia" a écrit dans le message de
news:%23Rl2QFu%
Bonjour Clive

Désolé de te répondre si tard mais je suis un peu débordé ces jours ci.

Tout d'abord merci pour ton aide et ta patience.

En fait je n'ai pas su créer de nouveau projet VB6 (je developpe en VB


sous
access et Outlook,
et j'ai uniquement une version Office 2000 Pro) => je sais pas comment
créer un nouveau projet, peut etre
je pense que je dois avoir besoin d'une version développer d'Office ?

Si je crée un formulaire dans mon projet Outlook(vbaProject.OTM, le pb
c'est que lorsque
j'execute mon formulaire, ce dernier garde le focus et je ne peux plus
accéder à la fenetre
Outllook pour envoyer / recevoir mes messages.

Bref j'ai tout de même repris ton code a savoir : la déclaration et les 3
sub routines:

Public WithEvents outApp As Outlook.Application
Sub Intialize_Handler()
Private Sub outApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
Private Sub outApp_NewMailEx(ByVal EntryIDCollection As String)

(J'ai copié tout ça dans CetteSessionOutlook)

Lorsque j'envoie un message ça marche , je passe par la Private Sub
outApp_ItemSend
par contre lorsque je reçoie un message rien ne se passe !!!

ps (j'ai bien coché la référence "Microsoft Outlook 9.0 Object Library")

@+
Alain



"Clive Lumb" a écrit dans le


message
de news:%23ALVcYE%
> Alain,
>
> Voici le code testé.
>
> NOTE: pour accéder à la liste des destinataires, expéditeurs etc si > > > Outlook2000 SP3, alors on va vous démander permission.
>
> Pour voir toutes les propriétés des messages, utiliser l'explorateur
> d'objets de VB (F2) et choisir la bibliothèque Outlook, puis regarder la
> classe "MailItem".
>
> Bon courage
> Clive
>
> ********************
> 'Créer un nouveau projet VB6
> 'Ajouter une référence à "Microsoft Outlook nn Object Library" au projet
> 'Créer un form avec 3 boutons de commande Command1, Command2 et Command3
> 'Coller ce code dans le form
> 'Lancer, appuyer sur le bouton "Surveillance", lancer Outlook et


attendre
de
> récevoir
> 'un mail ou essayer d'en envoyer
>
> Public WithEvents outApp As Outlook.Application
>
> Sub Intialize_Handler()
> Set outApp = Application
> End Sub
>
> Private Sub Command2_Click()
> 'Arrête la surveillance Outlook
> Set out_app = Nothing
> Me.Command1.Enabled = True
> Me.Command2.Enabled = False
> End Sub
>
> Private Sub Command3_Click()
> 'Arrête la surveillance Outlook et ferme le programme
> Set out_app = Nothing
> Unload Me
> End Sub
>
> Private Sub Form_Load()
> With Me
> .Width = 2500
> .Height = 1500
> .Command2.Enabled = False
> .Command1.Caption = "Surveillance"
> .Command2.Caption = "Pas de surveillance"
> .Command3.Caption = "Fermer"
> .Command1.Height = 350
> .Command2.Height = 350
> .Command3.Height = 350
> .Command1.Top = 0
> .Command2.Top = .Command1.Top + .Command1.Height * 1.1
> .Command3.Top = .Command2.Top + .Command2.Height * 1.1
> .Command1.Left = 0
> .Command2.Left = 0
> .Command3.Left = 0
> .Command1.Width = 1800
> .Command2.Width = 1800
> .Command3.Width = 1800
> End With
> End Sub
>
> Private Sub outApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
> Dim Dest As String
> Dest = Item.To
> Dest = "Vous envoyez un message à " & Dest
> MsgBox Dest
> End Sub
>
> Private Sub outApp_NewMailEx(ByVal EntryIDCollection As String)
> Dim mai As Object
> Dim intInitial As Integer
> Dim intFinal As Integer
> Dim strEntryId As String
> Dim intLength As Integer
>
> intInitial = 1
> intLength = Len(EntryIDCollection)
> MsgBox "Collection of EntryIds: " & EntryIDCollection
> intFinal = InStr(intInitial, EntryIDCollection, ",")
> Do While intFinal <> 0
> strEntryId = Strings.Mid(EntryIDCollection, intInitial,
(intFinal -
> intInitial))
> DoEvents
> MsgBox "EntryId: " & strEntryId
> Set mai = Application.Session.GetItemFromID(strEntryId)
> MsgBox mai.Subject
> intInitial = intFinal + 1
> intFinal = InStr(intInitial, EntryIDCollection, ",")
> Loop
> strEntryId = Strings.Mid(EntryIDCollection, intInitial, (intLength -
> intInitial) + 1)
> DoEvents
> MsgBox strEntryId
> Set mai = Application.Session.GetItemFromID(strEntryId)
> MsgBox mai.Subject
>
> End Sub
>
> Private Sub Command1_Click()
> 'Démarre la surveillance Outlook
> Call Intialize_Handler
> Me.Command1.Enabled = False
> Me.Command2.Enabled = True
> End Sub
>
> ********************
>
> "Xantia" a écrit dans le message
de
> news:%23d1erH%
> > Bonsoir Clive
> >
> > Bon je vais etre franc .. j'y arrive pas avec ton code
> > si tu arrives à le faire marcher j'aimerai bien avoir le
> > mode d'emploi ...
> >
> > @+
> >
> > Alain
> >
> > "Clive Lumb" a écrit dans le message de
> > news:e$1M%
> > > Alain,
> > > NewMailEx est un évenement de l'objet Ou_App, donc on ne l'appele
pas...
> > > Si tu regardes dans la liste déroulant des objets en haut de la
fenetre
> de
> > > code tu devrais trouver Out_App, ensuite
> > > dans les procédure tu trouveras NewMailEx
> > > Mettre "msgbox "Vous avez recu un mail" dans cette procédure pour


voir
> si
> > > cela marche
> > >
> > >
> > > "Xantia" a écrit dans le
message
> > de
> > > news:%
> > > > Bonjour Clive
> > > >
> > > > Je ne suis pas encore arrivé à faire tourner ton code
> > > > lorsque je fait le : Call outApp_NewMailEx
> > > > quel est le paramettre à mettre passer entre parenthèsese Call
> > > > outApp_NewMailEx ( ????)
> > > >
> > > > merci encore
> > > > @+
> > > > Alain
> > > >
> > > > "Clive Lumb" a écrit dans


le
> > > message
> > > > de news:
> > > > > Xantia,
> > > > >
> > > > > Oui tu as très bien compris, par contre l'exemple que je t'ai
donné
> > est
> > > > fait
> > > > > pour tourner sous VBA dans Outlook. C'est l'endroit le plus


simple
> de
> > le
> > > > > faire. Si tu comptes le faire tourner que sur ton poste il n'y a
> rien
> > à
> > > > > faire au niveau de la sécurité macro. Si c'est à distribuer sur
> > > plusieurs
> > > > je
> > > > > crois qu'il faut le "signer".
> > > > > Pour les opérations Access - dans un appli semblable j'ai créé


un
> > > ActiveX
> > > > > avec VB6 que j'ai déclaré comme référence dans Outlook.
> > > > >
> > > > >
> > > > >
> > > > > "Xantia" a écrit dans le
> > message
> > > > de
> > > > > news:
> > > > > > Merci Climb
> > > > > > ça m'a l'air génial ce bout de code mais j'ai encore quelques
> > > questions
> > > > > ...
> > > > > >
> > > > > > 1) Tout d'abord je n'arrive pas à l'exectuer (manuellement ou
> > lorsque
> > > je
> > > > > > reçois un Email)
> > > > > > J'ai cru comprendre qu'Outlook désactivait les macros (donc


mon
> code
> > > VB)
> > > > > >
> > > > > > Que dois je faire pour que ce code soit "autorisé" et


s'exécute
?
> > > > > >
> > > > > > 2) Merci de me confirmer que mon interprétation est la bonne
> > > > > >
> > > > > > J'ai compris que :
> > > > > >
> > > > > > outApp_NewMailEx et myOlApp_ItemSend sont 2 sub routines que


je
> dois
> > > > donc
> > > > > > simplement appeler
> > > > > > dans les evenements NewMail et ItemSend de l'objet
Application.
> > > > > > il me suffit de faire donc un Call outApp_NewMailEx.
> > > > > >
> > > > > > Puis de faire à l'interieur de chaque subroutine mes


opérations
de
> > > copy
> > > > > vers
> > > > > > ma base Access
> > > > > > en prenant les valeurs dans : mai.Subject
> > > > > > mai.From
> > > > > > mai.To ...
> > > > > >
> > > > > > Encore merci pour ton aide précieuse
> > > > > > @+
> > > > > > Alain
> > > > > >
> > > > > >
> > > > > > "Clive Lumb" a écrit
dans
> le
> > > > > message
> > > > > > de news:
> > > > > > > Voici ce que l'on trouve dans l'aide d'Outlook
> > > > > > > -----------------------
> > > > > > > L'exemple Microsoft Visual Basic pour Applications (VBA)
suivant
> > > > > illustre
> > > > > > > comment l'événement NewMailEx renvoie l'identificateur
d'entrée.
> > > Pour
> > > > > > > exécuter l'exemple, vous devez exécuter la routine
> > > Initialize_Handler.
> > > > > Cet
> > > > > > > événement se déclenche lors de la réception d'un ou


plusieurs
> > > messages
> > > > > > dans
> > > > > > > la Boîte de réception.
> > > > > > >
> > > > > > >
> > > > > > > Public WithEvents outApp As Outlook.Application
> > > > > > >
> > > > > > > Sub Intialize_Handler()
> > > > > > > Set outApp = Application
> > > > > > > End Sub
> > > > > > >
> > > > > > > Private Sub outApp_NewMailEx(ByVal EntryIDCollection As
String)
> > > > > > > Dim mai As Object
> > > > > > > Dim intInitial As Integer
> > > > > > > Dim intFinal As Integer
> > > > > > > Dim strEntryId As String
> > > > > > > Dim intLength As Integer
> > > > > > >
> > > > > > > intInitial = 1
> > > > > > > intLength = Len(EntryIDCollection)
> > > > > > > MsgBox "Collection of EntryIds: " & EntryIDCollection
> > > > > > > intFinal = InStr(intInitial, EntryIDCollection, ",")
> > > > > > > Do While intFinal <> 0
> > > > > > > strEntryId = Strings.Mid(EntryIDCollection,
intInitial,
> > > > > > (intFinal -
> > > > > > > intInitial))
> > > > > > > MsgBox "EntryId: " & strEntryId
> > > > > > > Set mai > Application.Session.GetItemFromID(strEntryId)
> > > > > > > MsgBox mai.Subject
> > > > > > > intInitial = intFinal + 1
> > > > > > > intFinal = InStr(intInitial, EntryIDCollection, ",")
> > > > > > > Loop
> > > > > > > strEntryId = Strings.Mid(EntryIDCollection, intInitial,
> > > > (intLength -
> > > > > > > intInitial) + 1)
> > > > > > > MsgBox strEntryId
> > > > > > > Set mai = Application.Session.GetItemFromID(strEntryId)
> > > > > > > MsgBox mai.Subject
> > > > > > >
> > > > > > > End Sub
> > > > > > > ------------------------------------L'exemple Microsoft


Visual
> > > > > > Basic/Visual
> > > > > > > Basic pour Applications (VBA) suivant montre comment annuler
> > > > l'événement
> > > > > > > ItemSend en réponse à l'entrée de l'utilisateur. L'exemple


de
> code
> > > > doit
> > > > > > être
> > > > > > > placé dans un module de classe et la routine
Initialize_handler
> > doit
> > > > > être
> > > > > > > appelée avant que la procédure événementielle puisse être
> appelée
> > > par
> > > > > > > Microsoft Outlook.
> > > > > > >
> > > > > > > Public WithEvents myOlApp As Outlook.Application
> > > > > > >
> > > > > > > Public Sub Initialize_handler()
> > > > > > > Set myOlApp = CreateObject("Outlook.Application")
> > > > > > > End Sub
> > > > > > >
> > > > > > > Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel As
> > > Boolean)
> > > > > > > Dim prompt As String
> > > > > > > prompt = "Are you sure you want to send " & Item.Subject &


"?"
> > > > > > > If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo


Then
> > > > > > > Cancel = True
> > > > > > > End If
> > > > > > > End Sub
> > > > > > >
> > > > > > >
> > > > > > > "Xantia" a écrit


dans
le
> > > > message
> > > > > > de
> > > > > > > news:
> > > > > > > > Bonjour Climb
> > > > > > > >
> > > > > > > > Merci pour l'info
> > > > > > > > J'ai commencé à regarder ça mais ça suscite des questions
> > > nouvelles
> > > > > > > >
> > > > > > > > En fait je cherche à copier "automatiquemet" dans une


table
> > access
> > > > les
> > > > > > > mails
> > > > > > > > dont l'adresse
> > > > > > > > d'expediteur (ou de destinataire) existent déja dans une
autre
> > de
> > > > mes
> > > > > > > table.
> > > > > > > >
> > > > > > > > est ce que je peux récupérer directement ces infos


d'Outlook
> (un
> > > > > espece
> > > > > > de
> > > > > > > > Me. )
> > > > > > > >
> > > > > > > > ou bien dois je déclarer des variables comme ci dessous


pour
> > > acceder
> > > > à
> > > > > > > tous
> > > > > > > > les champs
> > > > > > > > du mail ?
> > > > > > > > Dim OL_App As New Outlook.Application
> > > > > > > > Dim OL_Space As Outlook.NameSpace
> > > > > > > > Dim OL_Folder As Outlook.MAPIFolder
> > > > > > > > Dim OL_Folderx As Outlook.MAPIFolde
> > > > > > > > Set OL_Space = OL_App.GetNamespace("MAPI")
> > > > > > > > Set OL_Folderx > OL_Space.GetDefaultFolder(olFolderInbox)
> > > > > > > > Set OL_Folder = OL_Folderx
> > > > > > > >
> > > > > > > > dans ce cas comment faire pour adresser uniquement les
> nouveaux
> > > mail
> > > > > > (reçu
> > > > > > > > puis envoyés ?)
> > > > > > > >
> > > > > > > > merci pour ton aide
> > > > > > > > @+
> > > > > > > > Alain
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > "Clive Lumb" a


écrit
> > dans
> > > le
> > > > > > > message
> > > > > > > > de news:
> > > > > > > > > Regarder du coté du vba de Outlook.
> > > > > > > > > Les evenements NewMail et ItemSend de l'objet


Application
> > > > devraient
> > > > > > > faire
> > > > > > > > > ton affaire.
> > > > > > > > >
> > > > > > > > > Clive
> > > > > > > > >
> > > > > > > > > "Xantia" a écrit
> dans
> > le
> > > > > > message
> > > > > > > > de
> > > > > > > > > news:
> > > > > > > > > > Bonjour
> > > > > > > > > >
> > > > > > > > > > Je fait communiquer ma base Access avec la messagerie
> > > d'Outlook.
> > > > > > > > > > J'aimerais en fait "automatiser" mon code pour que dés
> > > réception
> > > > > > d'un
> > > > > > > > > nouvel
> > > > > > > > > > Email dans ma boite de réception et/ou dès que j'ai
> > > > éffectivement
> > > > > > > > envoyé
> > > > > > > > > un
> > > > > > > > > > E-mail
> > > > > > > > > > j'enclenche une action envers ma base Access.
> > > > > > > > > >
> > > > > > > > > > Que est le code VB qui me permet de détecter l'envoie
ou
> la
> > > > > > reception
> > > > > > > > de
> > > > > > > > > > mes messages ?
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > merci pour votre aide
> > > > > > > > > >
> > > > > > > > > > @+
> > > > > > > > > > Alain
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>




Avatar
Xantia
Bonlsoir Clive

ça y est presque je touche au but .....

Bon cette fois c'est bon j'arrive à déclencher l'évènement sur reception
mail et
à faire mes manips ave ma base ...
il ne me reste que 2 choses à régler:

1) j'ai déclaré : Public WithEvents myOlItems As Outlook.Items
Public WithEvents myOlItem As Outlook.MailItem

Je récupère les infos relatives au mail reçu avec :
Item.Bcc
Item.Subject
Item.To
Item.Body
par contre je n'arrive pas à récupérer l'adresse Email complète de
l'expéditeur .....

2) Y a t il une solution pour automatiser complètement mon code
et éviter (ou valider automatiquement) notamment la fameuse validation à
donner à Outlook pour accéder à mes adresses (sécurité Outlook2000 SP3
dont tu parlais)

Encore merci pour ton aide

@+
Alain



"Clive Lumb" a écrit dans le message de
news:uGQcLGv%
Alain,

Pas de problème....

Comme je soupçonnais depuis un moment tu n'utilises pas VB, mais VBA (Ici
c'est le groupe pour VB)....
Ce n'est pas grave, car ce que tu veux faire est tout à fait faisable avec
VBA.

(pour info, VB permet de créer des applications, VBA permet de contrôler


les
applications Office etc.. VB est compilé, VBA tourne en interpreté).

Alors en regardant les évenements du modèle Outlook 9 en VBA on ne voit


pas
NewMailEx (Ex="extended"), seulement NewMail qui ne rend pas le "item"
reçu - il semblerait que cela n'existe pas avant la version 2003.

Heureusement il y a une solution - l'évenement "ItemAdd" de la boite de
réception.
Ci-après un exemple de chez Microsoft, malheureusement en English....
Bon courage

The following steps create a rule that automatically forwards any mail you
receive outside of regular business hours to another e-mail address, such


as
the e-mail address you use at home, or to someone else who works the shift
after yours.


1.. On the Tools menu, point to Macro, and click Visual Basic Editor.


2.. In the Project - Project1 pane, double-click Project1, and
double-click Microsoft Outlook Objects.


3.. Double-click ThisOutlookSession to open a code window.


4.. In the code window, type the following code. Modify the line that
specifies the e-mail address; substitute the e-mail address you want


e-mail
forwarded to:



Public WithEvents myOlItems As Outlook.Items


Public Sub Application_Startup()

' Reference the items in the Inbox. Because myOlItems is declared
' "WithEvents" the ItemAdd event will fire below.
Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items

End Sub


Private Sub myOlItems_ItemAdd(ByVal Item As Object)

' If it's currently not between 9:00 A.M. and 5:00 P.M.
If Time() < #9:00:00 AM# Or Time() > #5:00:00 PM# Then

' Check to make sure it is an Outlook mail message, otherwise
' subsequent code will probably fail depending on what type
' of item it is.
If TypeName(Item) = "MailItem" Then

' Forward the item just received
Set myForward = Item.Forward

' Address the message
myForward.Recipients.Add ""

' Send it
myForward.Send

End If

End If

End Sub 5.. On the File menu, click Save VBAProject.otm.


6.. Close the Visual Basic Editor.


7.. Restart Outlook so that the code will run.


NOTE: For more information about how to make sure your code properly


handles
various types of items, please see the following article in the Microsoft
Knowledge Base:

Q222482 OL2000: How To Handle Unexpected Items in a Collection
The following considerations should be taken into account if you are
considering implementing a rules solution using Visual Basic for
Applications:

a.. Outlook must be running for the Visual Basic for Application code to
run. This is the same effect as using client-side rules in the Rules


Wizard.
If Outlook is not running at the time the message arrives, the rule will


not
work.


b.. Your custom rule may conflict with other rules you have set up using
the Rules Wizard. For example, if you are using Microsoft Exchange Server
and create a server-side rule that moves mail from a specific individual


to
a specific folder, the mail is moved on the server and never reaches the
Inbox. Therefore, the ItemAdd event does not run since an item is not


added
to the Inbox.


c.. The code runs regardless of how an item is added to the Inbox. For
example, if you work late one night and drag a message to your Inbox, the
message is forwarded to the other e-mail account.


d.. Outlook also has a NewMail event, but that event only runs when you
get a new mail notification. If you receive three messages at once, the
event only runs once. You can use the NewMail event to make sure that your
Visual Basic for Applications code only runs when you receive new


messages,
but you must add additional logic to the code to search for those messages
that haven't been read before. So unfortunately both events tend to have


an
unwanted side effect:


a.. The ItemAdd event makes it easy to act on all of the incoming


items,
but it also acts on those items you move to the Inbox yourself.


b.. The NewMail event does not run when you drag items to the Inbox,


but
it is more difficult to program a solution to take into account that there
are multiple items in the Inbox that your code must act on.



"Xantia" a écrit dans le message


de
news:%23Rl2QFu%
> Bonjour Clive
>
> Désolé de te répondre si tard mais je suis un peu débordé ces jours ci.
>
> Tout d'abord merci pour ton aide et ta patience.
>
> En fait je n'ai pas su créer de nouveau projet VB6 (je developpe en VB
sous
> access et Outlook,
> et j'ai uniquement une version Office 2000 Pro) => je sais pas comment
> créer un nouveau projet, peut etre
> je pense que je dois avoir besoin d'une version développer d'Office ?
>
> Si je crée un formulaire dans mon projet Outlook(vbaProject.OTM, le pb
> c'est que lorsque
> j'execute mon formulaire, ce dernier garde le focus et je ne peux plus
> accéder à la fenetre
> Outllook pour envoyer / recevoir mes messages.
>
> Bref j'ai tout de même repris ton code a savoir : la déclaration et les


3
> sub routines:
>
> Public WithEvents outApp As Outlook.Application
> Sub Intialize_Handler()
> Private Sub outApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
> Private Sub outApp_NewMailEx(ByVal EntryIDCollection As String)
>
> (J'ai copié tout ça dans CetteSessionOutlook)
>
> Lorsque j'envoie un message ça marche , je passe par la Private Sub
> outApp_ItemSend
> par contre lorsque je reçoie un message rien ne se passe !!!
>
> ps (j'ai bien coché la référence "Microsoft Outlook 9.0 Object Library")
>
> @+
> Alain
>
>
>
> "Clive Lumb" a écrit dans le
message
> de news:%23ALVcYE%
> > Alain,
> >
> > Voici le code testé.
> >
> > NOTE: pour accéder à la liste des destinataires, expéditeurs etc si > > > > Outlook2000 SP3, alors on va vous démander permission.
> >
> > Pour voir toutes les propriétés des messages, utiliser l'explorateur
> > d'objets de VB (F2) et choisir la bibliothèque Outlook, puis regarder


la
> > classe "MailItem".
> >
> > Bon courage
> > Clive
> >
> > ********************
> > 'Créer un nouveau projet VB6
> > 'Ajouter une référence à "Microsoft Outlook nn Object Library" au


projet
> > 'Créer un form avec 3 boutons de commande Command1, Command2 et


Command3
> > 'Coller ce code dans le form
> > 'Lancer, appuyer sur le bouton "Surveillance", lancer Outlook et
attendre
> de
> > récevoir
> > 'un mail ou essayer d'en envoyer
> >
> > Public WithEvents outApp As Outlook.Application
> >
> > Sub Intialize_Handler()
> > Set outApp = Application
> > End Sub
> >
> > Private Sub Command2_Click()
> > 'Arrête la surveillance Outlook
> > Set out_app = Nothing
> > Me.Command1.Enabled = True
> > Me.Command2.Enabled = False
> > End Sub
> >
> > Private Sub Command3_Click()
> > 'Arrête la surveillance Outlook et ferme le programme
> > Set out_app = Nothing
> > Unload Me
> > End Sub
> >
> > Private Sub Form_Load()
> > With Me
> > .Width = 2500
> > .Height = 1500
> > .Command2.Enabled = False
> > .Command1.Caption = "Surveillance"
> > .Command2.Caption = "Pas de surveillance"
> > .Command3.Caption = "Fermer"
> > .Command1.Height = 350
> > .Command2.Height = 350
> > .Command3.Height = 350
> > .Command1.Top = 0
> > .Command2.Top = .Command1.Top + .Command1.Height * 1.1
> > .Command3.Top = .Command2.Top + .Command2.Height * 1.1
> > .Command1.Left = 0
> > .Command2.Left = 0
> > .Command3.Left = 0
> > .Command1.Width = 1800
> > .Command2.Width = 1800
> > .Command3.Width = 1800
> > End With
> > End Sub
> >
> > Private Sub outApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
> > Dim Dest As String
> > Dest = Item.To
> > Dest = "Vous envoyez un message à " & Dest
> > MsgBox Dest
> > End Sub
> >
> > Private Sub outApp_NewMailEx(ByVal EntryIDCollection As String)
> > Dim mai As Object
> > Dim intInitial As Integer
> > Dim intFinal As Integer
> > Dim strEntryId As String
> > Dim intLength As Integer
> >
> > intInitial = 1
> > intLength = Len(EntryIDCollection)
> > MsgBox "Collection of EntryIds: " & EntryIDCollection
> > intFinal = InStr(intInitial, EntryIDCollection, ",")
> > Do While intFinal <> 0
> > strEntryId = Strings.Mid(EntryIDCollection, intInitial,
> (intFinal -
> > intInitial))
> > DoEvents
> > MsgBox "EntryId: " & strEntryId
> > Set mai = Application.Session.GetItemFromID(strEntryId)
> > MsgBox mai.Subject
> > intInitial = intFinal + 1
> > intFinal = InStr(intInitial, EntryIDCollection, ",")
> > Loop
> > strEntryId = Strings.Mid(EntryIDCollection, intInitial,


(intLength -
> > intInitial) + 1)
> > DoEvents
> > MsgBox strEntryId
> > Set mai = Application.Session.GetItemFromID(strEntryId)
> > MsgBox mai.Subject
> >
> > End Sub
> >
> > Private Sub Command1_Click()
> > 'Démarre la surveillance Outlook
> > Call Intialize_Handler
> > Me.Command1.Enabled = False
> > Me.Command2.Enabled = True
> > End Sub
> >
> > ********************
> >
> > "Xantia" a écrit dans le


message
> de
> > news:%23d1erH%
> > > Bonsoir Clive
> > >
> > > Bon je vais etre franc .. j'y arrive pas avec ton code
> > > si tu arrives à le faire marcher j'aimerai bien avoir le
> > > mode d'emploi ...
> > >
> > > @+
> > >
> > > Alain
> > >
> > > "Clive Lumb" a écrit dans le message


de
> > > news:e$1M%
> > > > Alain,
> > > > NewMailEx est un évenement de l'objet Ou_App, donc on ne l'appele
> pas...
> > > > Si tu regardes dans la liste déroulant des objets en haut de la
> fenetre
> > de
> > > > code tu devrais trouver Out_App, ensuite
> > > > dans les procédure tu trouveras NewMailEx
> > > > Mettre "msgbox "Vous avez recu un mail" dans cette procédure pour
voir
> > si
> > > > cela marche
> > > >
> > > >
> > > > "Xantia" a écrit dans le
> message
> > > de
> > > > news:%
> > > > > Bonjour Clive
> > > > >
> > > > > Je ne suis pas encore arrivé à faire tourner ton code
> > > > > lorsque je fait le : Call outApp_NewMailEx
> > > > > quel est le paramettre à mettre passer entre parenthèsese Call
> > > > > outApp_NewMailEx ( ????)
> > > > >
> > > > > merci encore
> > > > > @+
> > > > > Alain
> > > > >
> > > > > "Clive Lumb" a écrit


dans
le
> > > > message
> > > > > de news:
> > > > > > Xantia,
> > > > > >
> > > > > > Oui tu as très bien compris, par contre l'exemple que je t'ai
> donné
> > > est
> > > > > fait
> > > > > > pour tourner sous VBA dans Outlook. C'est l'endroit le plus
simple
> > de
> > > le
> > > > > > faire. Si tu comptes le faire tourner que sur ton poste il n'y


a
> > rien
> > > à
> > > > > > faire au niveau de la sécurité macro. Si c'est à distribuer


sur
> > > > plusieurs
> > > > > je
> > > > > > crois qu'il faut le "signer".
> > > > > > Pour les opérations Access - dans un appli semblable j'ai créé
un
> > > > ActiveX
> > > > > > avec VB6 que j'ai déclaré comme référence dans Outlook.
> > > > > >
> > > > > >
> > > > > >
> > > > > > "Xantia" a écrit dans


le
> > > message
> > > > > de
> > > > > > news:
> > > > > > > Merci Climb
> > > > > > > ça m'a l'air génial ce bout de code mais j'ai encore


quelques
> > > > questions
> > > > > > ...
> > > > > > >
> > > > > > > 1) Tout d'abord je n'arrive pas à l'exectuer (manuellement


ou
> > > lorsque
> > > > je
> > > > > > > reçois un Email)
> > > > > > > J'ai cru comprendre qu'Outlook désactivait les macros (donc
mon
> > code
> > > > VB)
> > > > > > >
> > > > > > > Que dois je faire pour que ce code soit "autorisé" et
s'exécute
> ?
> > > > > > >
> > > > > > > 2) Merci de me confirmer que mon interprétation est la bonne
> > > > > > >
> > > > > > > J'ai compris que :
> > > > > > >
> > > > > > > outApp_NewMailEx et myOlApp_ItemSend sont 2 sub routines que
je
> > dois
> > > > > donc
> > > > > > > simplement appeler
> > > > > > > dans les evenements NewMail et ItemSend de l'objet
> Application.
> > > > > > > il me suffit de faire donc un Call outApp_NewMailEx.
> > > > > > >
> > > > > > > Puis de faire à l'interieur de chaque subroutine mes
opérations
> de
> > > > copy
> > > > > > vers
> > > > > > > ma base Access
> > > > > > > en prenant les valeurs dans : mai.Subject
> > > > > > > mai.From
> > > > > > > mai.To ...
> > > > > > >
> > > > > > > Encore merci pour ton aide précieuse
> > > > > > > @+
> > > > > > > Alain
> > > > > > >
> > > > > > >
> > > > > > > "Clive Lumb" a écrit
> dans
> > le
> > > > > > message
> > > > > > > de news:
> > > > > > > > Voici ce que l'on trouve dans l'aide d'Outlook
> > > > > > > > -----------------------
> > > > > > > > L'exemple Microsoft Visual Basic pour Applications (VBA)
> suivant
> > > > > > illustre
> > > > > > > > comment l'événement NewMailEx renvoie l'identificateur
> d'entrée.
> > > > Pour
> > > > > > > > exécuter l'exemple, vous devez exécuter la routine
> > > > Initialize_Handler.
> > > > > > Cet
> > > > > > > > événement se déclenche lors de la réception d'un ou
plusieurs
> > > > messages
> > > > > > > dans
> > > > > > > > la Boîte de réception.
> > > > > > > >
> > > > > > > >
> > > > > > > > Public WithEvents outApp As Outlook.Application
> > > > > > > >
> > > > > > > > Sub Intialize_Handler()
> > > > > > > > Set outApp = Application
> > > > > > > > End Sub
> > > > > > > >
> > > > > > > > Private Sub outApp_NewMailEx(ByVal EntryIDCollection As
> String)
> > > > > > > > Dim mai As Object
> > > > > > > > Dim intInitial As Integer
> > > > > > > > Dim intFinal As Integer
> > > > > > > > Dim strEntryId As String
> > > > > > > > Dim intLength As Integer
> > > > > > > >
> > > > > > > > intInitial = 1
> > > > > > > > intLength = Len(EntryIDCollection)
> > > > > > > > MsgBox "Collection of EntryIds: " & EntryIDCollection
> > > > > > > > intFinal = InStr(intInitial, EntryIDCollection, ",")
> > > > > > > > Do While intFinal <> 0
> > > > > > > > strEntryId = Strings.Mid(EntryIDCollection,
> intInitial,
> > > > > > > (intFinal -
> > > > > > > > intInitial))
> > > > > > > > MsgBox "EntryId: " & strEntryId
> > > > > > > > Set mai > > Application.Session.GetItemFromID(strEntryId)
> > > > > > > > MsgBox mai.Subject
> > > > > > > > intInitial = intFinal + 1
> > > > > > > > intFinal = InStr(intInitial, EntryIDCollection,


",")
> > > > > > > > Loop
> > > > > > > > strEntryId = Strings.Mid(EntryIDCollection,


intInitial,
> > > > > (intLength -
> > > > > > > > intInitial) + 1)
> > > > > > > > MsgBox strEntryId
> > > > > > > > Set mai Application.Session.GetItemFromID(strEntryId)
> > > > > > > > MsgBox mai.Subject
> > > > > > > >
> > > > > > > > End Sub
> > > > > > > > ------------------------------------L'exemple Microsoft
Visual
> > > > > > > Basic/Visual
> > > > > > > > Basic pour Applications (VBA) suivant montre comment


annuler
> > > > > l'événement
> > > > > > > > ItemSend en réponse à l'entrée de l'utilisateur. L'exemple
de
> > code
> > > > > doit
> > > > > > > être
> > > > > > > > placé dans un module de classe et la routine
> Initialize_handler
> > > doit
> > > > > > être
> > > > > > > > appelée avant que la procédure événementielle puisse être
> > appelée
> > > > par
> > > > > > > > Microsoft Outlook.
> > > > > > > >
> > > > > > > > Public WithEvents myOlApp As Outlook.Application
> > > > > > > >
> > > > > > > > Public Sub Initialize_handler()
> > > > > > > > Set myOlApp = CreateObject("Outlook.Application")
> > > > > > > > End Sub
> > > > > > > >
> > > > > > > > Private Sub myOlApp_ItemSend(ByVal Item As Object, Cancel


As
> > > > Boolean)
> > > > > > > > Dim prompt As String
> > > > > > > > prompt = "Are you sure you want to send " & Item.Subject &
"?"
> > > > > > > > If MsgBox(prompt, vbYesNo + vbQuestion, "Sample") = vbNo
Then
> > > > > > > > Cancel = True
> > > > > > > > End If
> > > > > > > > End Sub
> > > > > > > >
> > > > > > > >
> > > > > > > > "Xantia" a écrit
dans
> le
> > > > > message
> > > > > > > de
> > > > > > > > news:
> > > > > > > > > Bonjour Climb
> > > > > > > > >
> > > > > > > > > Merci pour l'info
> > > > > > > > > J'ai commencé à regarder ça mais ça suscite des


questions
> > > > nouvelles
> > > > > > > > >
> > > > > > > > > En fait je cherche à copier "automatiquemet" dans une
table
> > > access
> > > > > les
> > > > > > > > mails
> > > > > > > > > dont l'adresse
> > > > > > > > > d'expediteur (ou de destinataire) existent déja dans une
> autre
> > > de
> > > > > mes
> > > > > > > > table.
> > > > > > > > >
> > > > > > > > > est ce que je peux récupérer directement ces infos
d'Outlook
> > (un
> > > > > > espece
> > > > > > > de
> > > > > > > > > Me. )
> > > > > > > > >
> > > > > > > > > ou bien dois je déclarer des variables comme ci dessous
pour
> > > > acceder
> > > > > à
> > > > > > > > tous
> > > > > > > > > les champs
> > > > > > > > > du mail ?
> > > > > > > > > Dim OL_App As New Outlook.Application
> > > > > > > > > Dim OL_Space As Outlook.NameSpace
> > > > > > > > > Dim OL_Folder As Outlook.MAPIFolder
> > > > > > > > > Dim OL_Folderx As Outlook.MAPIFolde
> > > > > > > > > Set OL_Space = OL_App.GetNamespace("MAPI")
> > > > > > > > > Set OL_Folderx > > OL_Space.GetDefaultFolder(olFolderInbox)
> > > > > > > > > Set OL_Folder = OL_Folderx
> > > > > > > > >
> > > > > > > > > dans ce cas comment faire pour adresser uniquement les
> > nouveaux
> > > > mail
> > > > > > > (reçu
> > > > > > > > > puis envoyés ?)
> > > > > > > > >
> > > > > > > > > merci pour ton aide
> > > > > > > > > @+
> > > > > > > > > Alain
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > "Clive Lumb" a
écrit
> > > dans
> > > > le
> > > > > > > > message
> > > > > > > > > de news:
> > > > > > > > > > Regarder du coté du vba de Outlook.
> > > > > > > > > > Les evenements NewMail et ItemSend de l'objet
Application
> > > > > devraient
> > > > > > > > faire
> > > > > > > > > > ton affaire.
> > > > > > > > > >
> > > > > > > > > > Clive
> > > > > > > > > >
> > > > > > > > > > "Xantia" a


écrit
> > dans
> > > le
> > > > > > > message
> > > > > > > > > de
> > > > > > > > > > news:
> > > > > > > > > > > Bonjour
> > > > > > > > > > >
> > > > > > > > > > > Je fait communiquer ma base Access avec la


messagerie
> > > > d'Outlook.
> > > > > > > > > > > J'aimerais en fait "automatiser" mon code pour que


dés
> > > > réception
> > > > > > > d'un
> > > > > > > > > > nouvel
> > > > > > > > > > > Email dans ma boite de réception et/ou dès que j'ai
> > > > > éffectivement
> > > > > > > > > envoyé
> > > > > > > > > > un
> > > > > > > > > > > E-mail
> > > > > > > > > > > j'enclenche une action envers ma base Access.
> > > > > > > > > > >
> > > > > > > > > > > Que est le code VB qui me permet de détecter


l'envoie
> ou
> > la
> > > > > > > reception
> > > > > > > > > de
> > > > > > > > > > > mes messages ?
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > merci pour votre aide
> > > > > > > > > > >
> > > > > > > > > > > @+
> > > > > > > > > > > Alain
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>




Avatar
Clive Lumb
Alain,

par contre je n'arrive pas à récupérer l'adresse Email complète de
l'expéditeur .....


Par "adresse e-mail complète" j'imagine que tu voudrais dire l'adresse de
messagérie () plutôt que le nom de la personne dans
le carnet d'adresses ?

oApp.ActiveInspector.CurrentItem.recipients(1).address donne l'adresse
e-mail du premier destinataire



2) Y a t il une solution pour automatiser complètement mon code
et éviter (ou valider automatiquement) notamment la fameuse validation


à
donner à Outlook pour accéder à mes adresses (sécurité Outlook2000 SP3
dont tu parlais)



La seule solution "simple" que j'ai trouvé c'est un produit qui s'appelle
"Redemption" qui simule les propriétés et méthodes d'Outlook à travers des
appels MAPI - ce qui contourne la sécurité.

On peut le télécharger ici: http://www.dimastr.com/redemption/ c'est gratuit
et affiche seulement une page d'info/licence lors de son installation.
Toute la doc est en Anglais, mais cela vaut le coup de piocher dedans

Voici un bout de code de chez moi qui fait ce que tu voudrais faire....
Noter qu'il y a des fonctions comme "GetNextChrono" et des contrôles comme
"Combo1" que je n'ai pas inclus - le code ne marchera pas comme ça, à toi de
t'en inspirer


Type DBRecord
RefChrono As String
Equipe As Integer
Numero As Integer
Annee As Integer
DateEnvoi As Date
Expediteur As String
Destinateur As String 'oui, je sais que cela devrait être
Destinataire....
CC As String
CCI As String
Sujet As String
Extrait As String
PiecesJointes As String
Pays As String
End Type

Dim MailDetails As DBRecord
Dim I As Integer
Dim Msg As String
Dim Num_Chrono As String
Dim rItem As Object
Dim rApp As Object
Dim rUser As Object
Dim oAppNs As Outlook.NameSpace
Dim oUser As Outlook.UserProperty
Dim MyName As String
Dim oApp As New Outlook.Application
Dim oExp As Outlook.Explorer
Dim oSel As Outlook.Selection ' You need a selection object for
getting the selection.
Dim oItem As Object ' You don't know the type yet.
Dim oMessage As Outlook.MailItem
Dim oInspector As Outlook.Inspector
Dim MyDialog As New Dialog


Me.GetSelectedItem.Enabled = False
Me.Command1.Enabled = False
Me.cmdSaisieManuelle.Enabled = False
Call Status("Recherche de messages", minfo)
Set oAppNs = oApp.GetNamespace("MAPI")
Set rApp = New Redemption.SafeCurrentUser
MyName = rApp.Name
If Len(MyName) = 0 Then
MyName = GetSetting("CTSChrono", "Settings", "LastUser", "Inconnu")
Else
SaveSetting "CTSChrono", "Settings", "LastUser", MyName
End If
Set oExp = oApp.ActiveExplorer ' Get the ActiveExplorer.
'Set oSel = oExp.Selection ' Get the selection.
If oApp.Inspectors.Count > 0 Then
Set oInspector = oApp.ActiveInspector
Set oItem = oInspector.CurrentItem
If oItem.Class = olMail Then
Set rItem = New Redemption.SafeMailItem
rItem.Item = oItem
'Set oMessage = oItem
Call Status("Trouvé mail à " & rItem.To, mOK)

With rItem
If Len(.To) = 0 Then
Msg = "Outlook ne veut pas me donner le nom du
destinataire !!" & vbCrLf & "Je sauve le brouillon pour l'activer"
MsgBox Msg, , "CTS Chrono"
rItem.Save
Else
End If
Msg = "Merci d'indiquer le pays/classment et confirmer
l'ajout au Chrono du message à " & vbCrLf & .To & "." & vbCr & "Sujet: " &
.Subject
Call Status("Confirmation", mQuestion)
MyDialog.lblMsg = Msg
MyDialog.Show vbModal
If ConfirmFlag Then
Call Status("Recherche détails", minfo)
DoEvents
MailDetails.Expediteur = MyName
MailDetails.DateEnvoi = Now()
MailDetails.Sujet = .Subject
If .Subject = "" Then
MsgBox "l'Objet est vide !!!", , "CTS Chrono"
End If
MailDetails.Destinateur = .To
If .Recipients(1).AddressEntry.Type = "SMTP" Then
MailDetails.Destinateur = MailDetails.Destinateur &
" <" & .Recipients(1).Address & ">"
End If
MailDetails.CC = .CC
MailDetails.CCI = .BCC
'Activer cette ligne pour envoyer un copie cachée à
qqu'un
'.BCC = "; " & .BCC
For I = 1 To oItem.Attachments.Count
MailDetails.PiecesJointes MailDetails.PiecesJointes & oItem.Attachments.Item(I).DisplayName & ", "
Next I
MailDetails.Equipe = Me.Combo1.ListIndex + 1
MailDetails.Annee = Year(Now())
MailDetails.Numero = GetNextChrono(MailDetails.Annee,
MailDetails.Equipe)
MailDetails.Pays = Pays
Num_Chrono = "E" & Trim$(Str$(MailDetails.Equipe)) & "."
& Format(MailDetails.Numero, "0000") & "CTS" &
Right$(Trim$(Str$(MailDetails.Annee)), 2)
Call Status(Num_Chrono, minfo)
MailDetails.RefChrono = Num_Chrono
MailDetails.Extrait = Left$(oItem.Body, 200)
Select Case oInspector.EditorType
Case Is = olEditorText
oItem.Body = AddRefInText(oItem.Body, "Notre/Our Ref
: " & Num_Chrono)
Case Is = olEditorRTF
oItem.Body = AddRefInText(oItem.Body, "Notre/Our Ref
: " & Num_Chrono)
Case Is = olEditorHTML
oItem.HTMLBody = AddRefInHTML(oItem.HTMLBody,
"Notre/Our Ref : " & Num_Chrono)
End Select
.Subject = "[" & Num_Chrono & "]: " & .Subject
MailDetails.Sujet = Left$(.Subject, 100)
Call Status("Ajout dans BD", minfo)
Call AddToChrono(MailDetails)
Clipboard.Clear
Clipboard.SetText Num_Chrono, vbCFText
Call Status(Num_Chrono & " terminé", mOK)
Else
Call Status("Annulé", mOK)
End If
End With
Set rItem = Nothing
Set oItem = Nothing
Set oInspector = Nothing
Else
Call Status("Pas de fenêtre mail ouverte !", mAlert)

End If

Else
Call Status("Pas de fenêtre mail ouverte !", mAlert)
End If
Set rApp = Nothing
Set rItem = Nothing
Set rApp = Nothing
Set rUser = Nothing
Set oAppNs = Nothing
Set oUser = Nothing
Set oApp = Nothing
Set oExp = Nothing
Set oSel = Nothing
Set oItem = Nothing
Set oMessage = Nothing
Set oInspector = Nothing
Set MyDialog = Nothing


Encore merci pour ton aide


de rien
Avatar
Xantia
Bonsoir Clive

SUPER GENiAL

ça marche

Bon je n'ai pas encore eu le temps d'essayer "redemption" mais je vais m'y
mettre.

J'ai adapté ton code pour l'adresse de messagerie (OutApp ne donnait rien)
Item.GetInspector.CurrentItem.Recipients(1).Address

Il va falloir que je trouve le truc pour éviter de devoir activer mes macro
chaque fosi que j'allume
mon PC et que je lance Outlook.
Il va aussi falloir que je regarde comment faire un addin de mon bout de
code pour pourvoir l'installer
facilement sans qu'on puisse le modifier.(c'est les projet Com ou quelque
chose comme ça je crois)

(et oui je démarre en VBA (et par la même occas VB et vb script) en
autodidacte depuis juillet dernier ..)

merci encore
@+
Alain


"Clive Lumb" a écrit dans le message de
news:O4G6Dp5%
Alain,

> par contre je n'arrive pas à récupérer l'adresse Email complète de
> l'expéditeur .....
Par "adresse e-mail complète" j'imagine que tu voudrais dire l'adresse de
messagérie () plutôt que le nom de la personne dans
le carnet d'adresses ?

oApp.ActiveInspector.CurrentItem.recipients(1).address donne l'adresse
e-mail du premier destinataire



> 2) Y a t il une solution pour automatiser complètement mon code
> et éviter (ou valider automatiquement) notamment la fameuse


validation
à
> donner à Outlook pour accéder à mes adresses (sécurité Outlook2000


SP3
> dont tu parlais)

La seule solution "simple" que j'ai trouvé c'est un produit qui s'appelle
"Redemption" qui simule les propriétés et méthodes d'Outlook à travers des
appels MAPI - ce qui contourne la sécurité.

On peut le télécharger ici: http://www.dimastr.com/redemption/ c'est


gratuit
et affiche seulement une page d'info/licence lors de son installation.
Toute la doc est en Anglais, mais cela vaut le coup de piocher dedans

Voici un bout de code de chez moi qui fait ce que tu voudrais faire....
Noter qu'il y a des fonctions comme "GetNextChrono" et des contrôles comme
"Combo1" que je n'ai pas inclus - le code ne marchera pas comme ça, à toi


de
t'en inspirer


Type DBRecord
RefChrono As String
Equipe As Integer
Numero As Integer
Annee As Integer
DateEnvoi As Date
Expediteur As String
Destinateur As String 'oui, je sais que cela devrait être
Destinataire....
CC As String
CCI As String
Sujet As String
Extrait As String
PiecesJointes As String
Pays As String
End Type

Dim MailDetails As DBRecord
Dim I As Integer
Dim Msg As String
Dim Num_Chrono As String
Dim rItem As Object
Dim rApp As Object
Dim rUser As Object
Dim oAppNs As Outlook.NameSpace
Dim oUser As Outlook.UserProperty
Dim MyName As String
Dim oApp As New Outlook.Application
Dim oExp As Outlook.Explorer
Dim oSel As Outlook.Selection ' You need a selection object for
getting the selection.
Dim oItem As Object ' You don't know the type yet.
Dim oMessage As Outlook.MailItem
Dim oInspector As Outlook.Inspector
Dim MyDialog As New Dialog


Me.GetSelectedItem.Enabled = False
Me.Command1.Enabled = False
Me.cmdSaisieManuelle.Enabled = False
Call Status("Recherche de messages", minfo)
Set oAppNs = oApp.GetNamespace("MAPI")
Set rApp = New Redemption.SafeCurrentUser
MyName = rApp.Name
If Len(MyName) = 0 Then
MyName = GetSetting("CTSChrono", "Settings", "LastUser",


"Inconnu")
Else
SaveSetting "CTSChrono", "Settings", "LastUser", MyName
End If
Set oExp = oApp.ActiveExplorer ' Get the ActiveExplorer.
'Set oSel = oExp.Selection ' Get the selection.
If oApp.Inspectors.Count > 0 Then
Set oInspector = oApp.ActiveInspector
Set oItem = oInspector.CurrentItem
If oItem.Class = olMail Then
Set rItem = New Redemption.SafeMailItem
rItem.Item = oItem
'Set oMessage = oItem
Call Status("Trouvé mail à " & rItem.To, mOK)

With rItem
If Len(.To) = 0 Then
Msg = "Outlook ne veut pas me donner le nom du
destinataire !!" & vbCrLf & "Je sauve le brouillon pour l'activer"
MsgBox Msg, , "CTS Chrono"
rItem.Save
Else
End If
Msg = "Merci d'indiquer le pays/classment et confirmer
l'ajout au Chrono du message à " & vbCrLf & .To & "." & vbCr & "Sujet: " &
.Subject
Call Status("Confirmation", mQuestion)
MyDialog.lblMsg = Msg
MyDialog.Show vbModal
If ConfirmFlag Then
Call Status("Recherche détails", minfo)
DoEvents
MailDetails.Expediteur = MyName
MailDetails.DateEnvoi = Now()
MailDetails.Sujet = .Subject
If .Subject = "" Then
MsgBox "l'Objet est vide !!!", , "CTS Chrono"
End If
MailDetails.Destinateur = .To
If .Recipients(1).AddressEntry.Type = "SMTP" Then
MailDetails.Destinateur = MailDetails.Destinateur


&
" <" & .Recipients(1).Address & ">"
End If
MailDetails.CC = .CC
MailDetails.CCI = .BCC
'Activer cette ligne pour envoyer un copie cachée à
qqu'un
'.BCC = "; " & .BCC
For I = 1 To oItem.Attachments.Count
MailDetails.PiecesJointes > MailDetails.PiecesJointes & oItem.Attachments.Item(I).DisplayName & ", "
Next I
MailDetails.Equipe = Me.Combo1.ListIndex + 1
MailDetails.Annee = Year(Now())
MailDetails.Numero = GetNextChrono(MailDetails.Annee,
MailDetails.Equipe)
MailDetails.Pays = Pays
Num_Chrono = "E" & Trim$(Str$(MailDetails.Equipe)) &


"."
& Format(MailDetails.Numero, "0000") & "CTS" &
Right$(Trim$(Str$(MailDetails.Annee)), 2)
Call Status(Num_Chrono, minfo)
MailDetails.RefChrono = Num_Chrono
MailDetails.Extrait = Left$(oItem.Body, 200)
Select Case oInspector.EditorType
Case Is = olEditorText
oItem.Body = AddRefInText(oItem.Body, "Notre/Our


Ref
: " & Num_Chrono)
Case Is = olEditorRTF
oItem.Body = AddRefInText(oItem.Body, "Notre/Our


Ref
: " & Num_Chrono)
Case Is = olEditorHTML
oItem.HTMLBody = AddRefInHTML(oItem.HTMLBody,
"Notre/Our Ref : " & Num_Chrono)
End Select
.Subject = "[" & Num_Chrono & "]: " & .Subject
MailDetails.Sujet = Left$(.Subject, 100)
Call Status("Ajout dans BD", minfo)
Call AddToChrono(MailDetails)
Clipboard.Clear
Clipboard.SetText Num_Chrono, vbCFText
Call Status(Num_Chrono & " terminé", mOK)
Else
Call Status("Annulé", mOK)
End If
End With
Set rItem = Nothing
Set oItem = Nothing
Set oInspector = Nothing
Else
Call Status("Pas de fenêtre mail ouverte !", mAlert)

End If

Else
Call Status("Pas de fenêtre mail ouverte !", mAlert)
End If
Set rApp = Nothing
Set rItem = Nothing
Set rApp = Nothing
Set rUser = Nothing
Set oAppNs = Nothing
Set oUser = Nothing
Set oApp = Nothing
Set oExp = Nothing
Set oSel = Nothing
Set oItem = Nothing
Set oMessage = Nothing
Set oInspector = Nothing
Set MyDialog = Nothing


> Encore merci pour ton aide
de rien




1 2