Applescript for sending mail to several recipients

Joined
Nov 1, 2023
Messages
1
Reaction score
0
Hi,
I am a beginner with using Applescript but I'd like to program a script that sends a mail message (always the same text and title) to several recipients, one by one, with Apple Mail. The script should retrieve the addresses from an Excel Sheet (or similar).

In a first step I asked Chat GPT for a code, it gave me this:

-- Spécifiez le chemin vers votre fichier Excel
set cheminFichierExcel to "Chemin:Vers:Votre:Fichier.xlsx"

-- Ouvrez le fichier Excel
tell application "Microsoft Excel"
activate
open workbook workbook file name cheminFichierExcel
set feuilleExcel to active sheet
set dernierLigne to (get end row of used range of feuilleExcel)
end tell

-- Créez un nouvel e-mail avec le même sujet et le même corps pour chaque destinataire
tell application "Mail"
set sujetMessage to "Sujet de votre e-mail"
set corpsMessage to "Corps de votre e-mail."

-- Parcourez les lignes du fichier Excel pour extraire les adresses e-mail
repeat with i from 1 to dernierLigne
set cellule to cell i of column "A" of feuilleExcel -- Modifier "A" pour correspondre à la colonne contenant les e-mails
set contenuCellule to value of cellule as string
if contenuCellule is not equal to "" then
set nouveauMessage to make new outgoing message with properties {subject:sujetMessage, content:corpsMessage}
make new to recipient at nouveauMessage with properties {address:contenuCellule}
send nouveauMessage
end if
end repeat

-- Fermez le fichier Excel
close active workbook saving no
end tell

Unfortunately this script dosen't work, I get a syntax error message (in the line "set cellule to cell i of column "A" of...", the i is highlighted.

Can anybody help me to have this work?

Thanks,

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top