Applescript 邮件附件未发送

Applescript Mail Attachment Not Sending

以下 Applescript 成功发送电子邮件但未附加 wav 文件。你能告诉我我做错了什么吗?谢谢。

    tell application "Mail"

    set theSubject to "Voicemail"
    set theContent to read (the POSIX path of "/private/tmp/voice.tgCrnv/BODY.txt")
    set theAddress to "me@example1.com"
    set theSender to "me@example2.com"
    set theAttachmentFile to (POSIX file "/private/tmp/voice.tgCrnv/msg_1bb3b4f2-c6b1-4012-89c0-a19177cc6ca2.wav") as string

    set msg to make new outgoing message with properties {subject:theSubject, content:theContent, visible:false, sender:theSender}

    tell msg to make new to recipient at end of every to recipient with properties {address:theAddress}
    tell msg to make new attachment with properties {file name:theAttachmentFile as alias}

    send msg
end tell

我已经稍微调整了您的脚本,我相信如果您在进行任何编辑以适应您自己的编码风格之前先按原样尝试它,我相信它会起作用(显然,请填写适当的电子邮件地址)。

重要的功能更改是在声明新的 outgoing message 时将 visible 设置为 true;并定位 outgoing messagecontent 以附加文件。

为了良好的编码习惯,我将变量声明移到 tell application 块之外(不需要告诉 Mail 设置这些变量,所以不要).

最后,我将代码文本重新格式化为我更习惯的格式以提高可读性。

    set theSubject to "Voicemail"
    set theContent to read "/private/tmp/voice.tgCrnv/BODY.txt"
    set theAddress to "me@example1.com"
    set theSender to "me@example2.com"
    set theAttachmentFile to POSIX file "/private/tmp/voice.tgCrnv/msg_1bb3b4f2-c6b1-4012-89c0-a19177cc6ca2.wav" as alias

    tell application "Mail" to tell (make new outgoing message with properties ¬
        {subject:theSubject, content:theContent, visible:true, sender:theSender})

        make new to recipient at end of to recipients ¬
            with properties {address:theAddress}

        tell its content to make new attachment at after the last paragraph ¬
            with properties {file name:theAttachmentFile}

        send
    end tell

告诉我进展如何。

这对我有用

set theSubject to "Voicemail"
set theContent to read "/private/tmp/voice.tgCrnv/BODY.txt"
set theAddress to "me@example1.com"
set theSender to "me@example2.com"
set theAttachmentFile to "/private/tmp/voice.tgCrnv/msg_1bb3b4f2-c6b1-4012-89c0-a19177cc6ca2.wav" as POSIX file as alias

tell application "Mail"
    set msg to make new outgoing message with properties ¬
        {subject:theSubject, content:theContent, visible:false, sender:theSender}
    tell msg
        make new to recipient at end of every to recipient with properties {address:theAddress}
        make new attachment at end of last character of content with properties ¬
            {file name:theAttachmentFile}
    end tell
    delay 1
    send msg
end tell

FWIW:更大的文件需要更长的延迟。 10mb - 我知道,太大了,但是...... - 需要超过 8 秒的延迟。