Mass mailing with Applescript and Outlook

Door MtC op maandag 24 februari 2014 15:06 - Reacties (4)
Categorie: scripting, Views: 3.025

If you want to send the same mail, with the same attachment, to multiple people, you can use the script below.
The list of addresses is a simple text file, with each address on a new line.
In the body, for newlines use <br> when you have Outlook set up to use HTML format. When Outlook is set up to send mail as plain text, use \n.

An example would be:


AppleScript:
1
set mailContent to "Hi,<br>this is a new line"

for html

or

AppleScript:
1
set mailContent to "Hi,\nthis is a new line"

for plain text



AppleScript:
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
on run {input, parameters}
  set mailAddresses to paragraphs of (read (file "Data:Users:myuser:Documents:mymailaddresses.txt"))
  repeat with nextLine in mailAddresses
    if length of nextLine is greater than 0 then
      tell application "Microsoft Outlook"
        
        set mailSubject to "some subject" -- the subject
        set mailContent to "some content" -- the content
        set mailAddress to nextLine -- the receiver 
        set mailSignatureName to "mySignatureName" -- the signature name
        set mailAttachment to "Data:Users:myuser:Documents:myattachm.ent" -- the attachment path
        
        set myMessage to make new outgoing message with properties {subject:mailSubject, content:mailContent}
        
        make new recipient at myMessage with properties {email address:{address:mailAddress}}
        make new attachment at the end of myMessage with properties {file:mailAttachment}
        
        send myMessage
      end tell
      
      delay 10
    
    end if
  
  end repeat
  
  return input

end run