Mail mit Anhang per Apple Script versenden: Anhang wird nicht eingefügt

Hallo,

ich habe ein Apple Script, mit dem ich eine Mail inklusive Anhang versenden möchte (wird in einem VBA Code aufgerufen, um einen Serienbrief als PDF zu versenden). Es funktioniert auch soweit ganz gut, bis auf die Tatsache, dass der Anhang nicht in die Mail eingebunden wird.

Ich habe das Standard Mail Programm von Apple verwendet.

Das Betriebssystem ist MacOs Ventura 13.1


Hat jemand eine Idee woran das liegen könnte ?


Im Folgenden das Skript das ich verwende.



tell application "Mail"
set NewMail to make new outgoing message with properties {content:"Hello World",  subject:"DiesUndDas" , visible:true}
tell NewMail
make new to recipient at end of to recipients with properties {address:"abc@def.de"}
tell NewMail
make new attachment with properties {file name:"/Users/frodo/test.pdf" as alias} at after the last paragraph
end tell
delay 1
end tell
end tell


Gepostet am 12. Feb. 2023 09:51

Antworten
Frage gekennzeichnet als Höchstrangige Antwort

Gepostet am 12. Feb. 2023 10:59

Dieser Fehler tritt auf, wenn das Mail-Programm nicht in der Lage ist, den Dateityp als Alias zu referenzieren. Eine Möglichkeit, dieses Problem zu beheben, besteht darin, den Dateityp explizit als POSIX-Pfad anzugeben:


tell application "Mail" to quit
delay 1
tell application "Mail"
    activate
    set NewMail to make new outgoing message with properties {content:"Hello World", subject:"DiesUndDas", visible:true}
    tell NewMail
        make new to recipient at end of to recipients with properties {address:"abc@def.de"}
        set attachmentPath to (POSIX file "/Users/frodo/test.pdf")
        if exists attachmentPath then
            make new attachment with properties {file name:attachmentPath} at after the last paragraph
        else
            display dialog "File not found: " & "/Users/frodo/test.pdf"
        end if
    end tell
    delay 1
end tell


9 Antworten
Frage gekennzeichnet als Höchstrangige Antwort

12. Feb. 2023 10:59 als Antwort auf abyni

Dieser Fehler tritt auf, wenn das Mail-Programm nicht in der Lage ist, den Dateityp als Alias zu referenzieren. Eine Möglichkeit, dieses Problem zu beheben, besteht darin, den Dateityp explizit als POSIX-Pfad anzugeben:


tell application "Mail" to quit
delay 1
tell application "Mail"
    activate
    set NewMail to make new outgoing message with properties {content:"Hello World", subject:"DiesUndDas", visible:true}
    tell NewMail
        make new to recipient at end of to recipients with properties {address:"abc@def.de"}
        set attachmentPath to (POSIX file "/Users/frodo/test.pdf")
        if exists attachmentPath then
            make new attachment with properties {file name:attachmentPath} at after the last paragraph
        else
            display dialog "File not found: " & "/Users/frodo/test.pdf"
        end if
    end tell
    delay 1
end tell


12. Feb. 2023 10:20 als Antwort auf PreCognition

Habe das Mail Programm komplett geschlossen. Es geht nach ausführen des Skripts auch wieder auf, der Text ist wie er sein soll, aber weiterhin ohne Anhang.

An der Stelle des Anhangs ist nur eine Leerzeile.


Ich habe es auch schon mit Outlook probiert, da werden allerdings sämtliche Zeilenumbrüche des Textes entfernt. Und der Anhang ist ebenfalls nicht da.


Ich habe den Pfad nochmals überprüft (im Terminal mit ls anzeigen lassen, der passt)

Dieser Thread wurde vom System oder dem Community-Team geschlossen. Du kannst alle Beiträge positiv bewerten, die du hilfreich findest, oder in der Community nach weiteren Antworten suchen.

Mail mit Anhang per Apple Script versenden: Anhang wird nicht eingefügt

Willkommen in der Apple Support Community
Ein Forum, in dem Apple-Kunden sich gegenseitig mit ihren Produkten helfen. Melde dich mit deinem Apple Account an, um Mitglied zu werden.