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
| (* Envoi automatique d'emails à partir d'une liste d'adresse
1 - lecture d'un fichier texte avec 3 lignes :
a) le nom/chemin d'un fichier Excel (liste adresses)
b) le nom/chemin d'un fichier Word (contenu de l'email)
c) le titre de l'email
2 - Lecture du fichier Word pour récupération du texte
3 - lecture du fichier Excel pour lecture des 50 adresses non encore utilisées
4 - Préparation et envoi de l'email
5 - Enregistrement dans Excel des adresses utilisées
*)
property F_Texte : "Users:imac27:Desktop:test:Prefs_mail.txt" -- emplacement du fichier texte
property Paquet : 10 -- nombre maximum d'adresses simultanées
global F_Excel, F_Word, Titre-- variables globales
global L_Debut, L_Fin, Mes_Adresses
-- script principal
Lecture_Txt()
Lecture_Word(F_Word)
set L_Debut to 1
set L_Fin to 1
set Mes_Adresses to {}
Lecture_XL_Adresses(F_Excel)
tell application "Mail"
activate
set Mon_Email to make new outgoing message with properties {visible:true, subject:Titre, content:the clipboard}
tell Mon_Email
repeat with Une_adresse in Mes_Adresses
make new to recipient at end of to recipients with properties {name:"", address:Une_adresse}
end repeat
-- pour les test l'instruction send est en commentaire !
-- send
end tell
end tell
Maj_Excel()
-- fin du script principal
on Lecture_Txt() -- lit le fichier texte dans les variables F_Excel, F_Word et Titre
try
set Lignes to paragraphs of (read file F_Texte)
set F_Excel to item 1 of Lignes
set F_Word to item 2 of Lignes
set Titre to item 3 of Lignes
end try
end Lecture_Txt
on Lecture_Word(f) -- lecture du fichier Word et renvoi le contenu dans le presse papier
try
tell application "Microsoft Word"
open file f
activate
end tell
tell application "System Events" to tell process "Microsoft Word"
keystroke "a" using {command down}
keystroke "c" using {command down}
end tell
tell application "Microsoft Word" to close front window
end try
end Lecture_Word
on Lecture_XL_Adresses(f) -- lecture du fichier Excel avec récupération des numéros lignes début, fin et la liste des adresse
tell application "Microsoft Excel"
open file f
activate
tell sheet 1 of front document
set Nb_Lignes to first row index of (get end (last cell of column 1) direction toward the top)
set L_Debut to first row index of (get end (last cell of column 2) direction toward the top)
set L_Fin to L_Debut + Paquet
if L_Fin > Nb_Lignes then set L_Fin to Nb_Lignes
set Mes_Adresses to (value of range ("A" & L_Debut & ":A" & L_Fin))
end tell
end tell
end Lecture_XL_Adresses
on Maj_Excel() -- met à jour les lignes Excel traitees, enregsitre et ferme
set Date_Jour to short date string of (current date)
tell application "Microsoft Excel"
tell sheet 1 of front document
set value of range ("B" & L_Debut & ":B" & L_Fin) to Date_Jour
end tell
close active workbook saving yes
end tell
end Maj_Excel |
Partager