2017-05-12 5 views
0

Ich versuche, mehrere Anhänge zu einer E-Mail in Applescript hinzuzufügen. Ich setze den Betreff oben auf Ordner und Wochennummer.Apple Mail-Anwendung, Hinzufügen mehrerer Anlagen

set {b, c} to {"1/1/1000", 364876} 
 
set {year:yy, month:mm, day:dd} to (current date) 
 
set yy to text 3 thru 4 of (yy as text) 
 
set d to ((((current date) - (date b)) div days + c) div 7) + 1 
 
set e to ((((date ("1/1/" & (year of the (current date)) as string)) - (date b)) div days + c) div 7) + 1 
 
set weekCode to (yy & (d - e) as text) 
 
set rSpace to " 
 
" 
 
set theSubject to "folder Week " & (text 3 thru 4 of weekCode) 
 

 
tell application "Finder" 
 
\t set folderPath to folder ((get (path to home folder) as Unicode text) & "Documents:folder" as Unicode text) 
 
\t set thefList to "" 
 
\t set fcount to 1 
 
\t repeat 
 
\t \t try 
 
\t \t \t set theFile to ((file fcount) in folderPath as alias) 
 
\t \t \t set theFile to name of theFile 
 
\t \t \t if thefList is "" then 
 
\t \t \t \t set thefList to theFile 
 
\t \t \t else 
 
\t \t \t \t set thefList to thefList & " 
 
" & theFile 
 
\t \t \t end if 
 
\t \t \t set fcount to (fcount + 1) 
 
\t \t on error 
 
\t \t \t set fcount to (fcount - 1) 
 
\t \t \t exit repeat 
 
\t \t end try 
 
\t end repeat 
 
\t 
 
\t --return thefList 
 
\t set theAttachment to theFile 
 
end tell 
 

 
repeat (fcount - 1) times 
 
\t set rSpace to " 
 
" & rSpace 
 
end repeat 
 

 

 
tell application "Mail" 
 
\t activate 
 
\t set theMessage to make new outgoing message with properties {visible:true, sender:"[email protected]", subject:theSubject, content:rSpace} 
 
\t 
 
\t 
 
\t tell theMessage 
 
\t \t make new to recipient with properties {address:"[email protected]"} 
 
\t \t set acount to 1 
 
\t \t repeat fcount times 
 
\t \t \t 
 
\t \t \t try 
 
\t \t \t \t make new attachment with properties {file name:(paragraph acount of thefList)} at after the last word of the paragraph acount 
 
\t \t \t \t set message_attachment to 0 
 
\t \t \t on error errmess -- oops 
 
\t \t \t \t log errmess -- log the error 
 
\t \t \t \t set message_attachment to 1 
 
\t \t \t end try 
 
\t \t \t log "message_attachment = " & acount 
 
\t \t \t set acount to (acount + 1) 
 
\t \t end repeat 
 
\t \t 
 
\t \t send 
 
\t end tell 
 
end tell

Es ist das Hinzufügen nicht die Anlagen, aber es ist die E-Mail zu senden.

Wie kann ich das Programm korrigieren, um die Anhänge hinzuzufügen?

Antwort

0

Es gibt ein allgemeines Missverständnis:

Die Befestigung einer Nachricht muss ein alias Verweis auf eine Datei anstatt einen String Dateinamen.

Der Code, um die Dateien und erstellen Sie die neuen Zeilen in der Nachricht zu bekommen

set documentsFolder to path to documents folder 
tell application "Finder" 
    set folderPath to folder "folder" of documentsFolder 
    set attachmentList to files of folderPath as alias list 
end tell 

set rSpace to "" 
repeat (count attachmentList) - 1 times 
    set rSpace to rSpace & return 
end repeat 

und der Code

reduziert werden, um die Nachricht erstellen auch reduziert werden kann (I kommentierte aus der send Linie)

tell application "Mail" 
    activate 
    set theMessage to make new outgoing message with properties {visible:true, sender:"[email protected]", subject:theSubject, content:rSpace} 
    tell theMessage 
     make new to recipient with properties {address:"[email protected]"} 
     set acount to 1 
     repeat with anAttachment in attachmentList 
      make new attachment with properties {file name:anAttachment} at after the last word of the paragraph acount 
      log "message_attachment = " & acount 
      set acount to (acount + 1) 
     end repeat 

     -- send 
    end tell 
end tell 
+0

Vielen Dank Vadian! –

Verwandte Themen