1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
'---------------------------------------------------------------------------------------
' Procedure : Application_ItemSend
' Author : OCTU
'---------------------------------------------------------------------------------------
'
If Not Item.Class = olMail Then GoTo Fin
'on teste le sujet
If InStr(1, Item.Subject, "contrat semaine", vbTextCompare) Then
' voir ici
' <a href="https://www.developpez.net/forums/blogs/191381-oliv/b4076/inserer-signature-lemail-actif-outlook-2016" target="_blank">https://www.developpez.net/forums/bl...f-outlook-2016</a>
Call InsertSignature(Item, "contrat")
Item.Save
ElseIf InStr(1, Item.Subject, "salaire mois de", vbTextCompare) Then
Call InsertSignature(Item, "salaire")
Item.Save
End If
'on ajoute des PJ selon l'adresse Email du premier destinataire
EmailDest = Split(GetSMTPAddressForRecipient(Item.Recipients(1)), "@")(0)
Dim MonDossierPJ
MonDossierPJ = "C:\Users\PC - Bureau\Desktop\a envoyer\"
Set Fso = CreateObject("Scripting.FileSystemObject")
Set AFolder = Fso.GetFolder(MonDossierPJ)
For Each Afile In AFolder.Files
If InStr(1, Afile, EmailDest, vbTextCompare) > 0 Then
Item.Attachments.Add (Afile.Path)
End If
Next Afile
Fin:
End Sub
' voir ici
' <a href="https://www.developpez.net/forums/blogs/191381-oliv/b4076/inserer-signature-lemail-actif-outlook-2016" target="_blank">https://www.developpez.net/forums/bl...f-outlook-2016</a>
Function GetSMTPAddressForRecipient(recip As Outlook.Recipient) As String
'---------------------------------------------------------------------------------------
' Procedure : GetSMTPAddressForRecipient
' Author : Oliv-
' Date : 21/01/2015
' Purpose : Obtenir l'adresse SMTP =xxx@xxx.xxx
'---------------------------------------------------------------------------------------
'Dim recip As Outlook.Recipient
'pas de adresse SMTP si Contact d'origine EXCHANGE mais copié dans Pop
GetSMTPAddressForRecipient = ""
On Error GoTo Fin
Dim PA As Outlook.PropertyAccessor
Const PR_SMTP_ADDRESS As String = _
"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set PA = recip.PropertyAccessor
'Debug.Print recip.Name & " SMTP=" _
& pa.GetProperty(PR_SMTP_ADDRESS)
GetSMTPAddressForRecipient = PA.GetProperty(PR_SMTP_ADDRESS)
Fin:
If GetSMTPAddressForRecipient = "" Then GetSMTPAddressForRecipient = recip
End Function
Sub InsertSignature(objMail As MailItem, SignatureName As String)
'---------------------------------------------------------------------------------------
' Procedure : InsertSignature
' Author : OLiv
' Version : 2
' Date : 09/06/2020
' Purpose : Ajout d'une signature pour OUTLOOK 2010,2013,2016,365
'---------------------------------------------------------------------------------------
'
Dim wd As Object, obSelection As Object
Dim oBookmarks As Object, oBookmark As Object 'Word.Bookmark
Dim enviro, strSigFilePath
Const wdStory = 6
Const wdParagraph = 4
Const wdGoToBookmark = -1
Const wdExtend = 1
Const wdSortByName = 0
enviro = CStr(Environ("appdata"))
strSigFilePath = enviro & "\Microsoft\Signatures\"
Set wd = objMail.GetInspector.WordEditor
Set obSelection = wd.Application.Selection
Set oBookmarks = wd.Bookmarks
On Error Resume Next
Set oBookmark = oBookmarks("_MailAutoSig")
On Error GoTo 0
If oBookmark Is Nothing Then
Set obSelection = wd.Application.Selection
obSelection.Move wdStory, -1
obSelection.Move wdParagraph, 1
obSelection.Paragraphs.Add
obSelection.Move wdParagraph, 1
Set oBookmark = obSelection.Bookmarks.Add("_MailAutoSig", obSelection.Range)
oBookmark.Range.Text = "_Signature"
oBookmark.End = wd.Range.End
End If
If Dir(strSigFilePath & SignatureName & ".htm", vbNormal) <> "" Then
'oBookmark.Select
Dim orng As Object 'Word.Range
Set orng = wd.Range
orng.Start = orng.Bookmarks("_MailAutoSig").Range.Start
orng.End = orng.Bookmarks("_MailAutoSig").Range.End
orng.InsertFile FileName:=strSigFilePath & SignatureName & ".htm", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
orng.End = wd.Range.End
With wd.Bookmarks
.Add Range:=orng, Name:="_MailAutoSig"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
'On Error Resume Next
'Set oBookmark = wd.Bookmarks("_MailAutoSig")
' oBookmark.End = wd.Range.End
'oBookmark.Select
obSelection.Move wdStory, -1
End If
End Sub |
Partager