gpt4 book ai didi

email - 通过 AppleScript 发送带有附件的电子邮件

转载 作者:行者123 更新时间:2023-12-02 01:32:13 24 4
gpt4 key购买 nike

所以我希望能够使用 applescript 发送带有附件的电子邮件。我有一位老师经常让我们做实验,并要求我们通过电子邮件发送实验,所以我决定将 hazel 和 applescript 结合起来,让这件事变得更容易。

基本上,当我将文档导出到文件夹中的 pdf 格式时,hazel 会检测到它并将其发送到另一个文件夹,然后该文件夹调用发送带有附件的电子邮件所需的脚本。完成后,hazel 会将文件放回到原始文件夹中,并将 _sent 附加到名称中,以便它不会再次发送。 (除非文件刚刚导出为 pdf,否则该文件夹始终为空)

我的问题是文件未附加到电子邮件中。 (大多数时候,我的脚本会出现错误,表明它没有成功运行,但这不是重点)。

我在使用自动化程序时遇到了同样的问题,文件未附加。我尝试了几个代码,但总是遇到同样的问题。电子邮件已发送,未附加任何文件。这是代码:

tell application "Finder"
set folderPath to folder "Macintosh HD:Users:user_directory:Desktop:Send_Mail"
set fileList to name of file 1 in folderPath
end tell

set theSubject to fileList
set theBody to "Hello sir. Here is my " & fileList
set theAddress to "Some Email"
set theAttachment to fileList
set theSender to "Some Sender"

tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return, visible:true}
tell theNewMessage
set visibile to true
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress}
try
make new attachment with properties {file name:fileList} at after the last word of the last paragraph
set message_attachment to 0
log "message_attachment = " & message_attachment
on error
set message_attachment to 1
end try
#tell content
# make new attachment with properties {file name:theAttachment, path:fileList}

#end tell
#send
end tell
end tell

我在事件日志中收到的唯一消息是“缺失值”。我不明白可能会缺少什么。

最佳答案

您混淆了文件名和文件路径 - 附件的文件名属性是要附加的文件。您还应该在 try 语句中记录所有错误,以便您可以看到它是什么 - 例如,尝试使用附件的 Finder 引用而不是别名时会收到错误。

tell application "Finder"
set folderPath to folder "Macintosh HD:Users:user_directory:Desktop:Send_Mail:"
set theFile to first file in folderPath as alias
set fileName to name of theFile
end tell

set theSubject to fileName
set theBody to "Hello sir. Here is my " & fileName
set theAddress to "Some Email"
set theAttachment to theFile
set theSender to "Some Sender"

tell application "Mail"
set theNewMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return, visible:true}
tell theNewMessage
set visibile to true
set sender to theSender
make new to recipient at end of to recipients with properties {address:theAddress}
try
make new attachment with properties {file name:theAttachment} at after the last word of the last paragraph
set message_attachment to 0
on error errmess -- oops
log errmess -- log the error
set message_attachment to 1
end try
log "message_attachment = " & message_attachment
#send
end tell
end tell

关于email - 通过 AppleScript 发送带有附件的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10063266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com