指定发件人生成新邮件时出现错误BCC收件人问题求助
修复方案及修改后的脚本
以下是针对你遇到的问题的修复脚本,以及关键改动说明:
#!/bin/bash # script called with arguments # to_address subject filename function realpath { echo $(cd $(dirname "$1"); pwd)/$(basename "$1"); } atfile=$(realpath "$3") echo "Attachment file: [$atfile]" cat <<ENDSCRIPT | osascript tell application "Mail" activate # 通过邮箱地址精准匹配目标账户对象,支持带名称的账户配置 set theAccount to account whose address is "mymailaccount@xyz" # 创建新邮件时直接绑定目标发件人账户,避免随机选账户触发错误BCC set newMessage to make new outgoing message with properties {sender:theAccount, visible:true} tell newMessage # 清空创建邮件时自动生成的错误BCC条目 delete every bcc recipient set subject to "$2" set content to "" make new to recipient with properties {address:"$1"} make new bcc recipient with properties {address:"mymailaccount@xyz"} # 使用预处理后的绝对路径添加附件,避免路径问题 make new attachment with properties {file name:("$atfile" as POSIX file as alias)} delay 1 end tell end tell ENDSCRIPT
关键修复点
创建邮件时直接指定发件人账户
不再依赖后续修改sender属性,而是在make new outgoing message时通过with properties {sender:theAccount}直接绑定目标账户。同时用account whose address is "xxx"获取完整账户对象,解决了只有纯邮箱地址才能设置发件人的问题,不管账户配置里是否包含名称都能精准匹配。清除自动生成的错误BCC
在添加自定义BCC前执行delete every bcc recipient,彻底删除创建邮件时因随机账户触发的自动密送条目,避免出现重复BCC。优化附件路径
直接使用脚本中已处理为绝对路径的$atfile添加附件,比原脚本的相对路径更可靠,减少文件找不到的概率。简化延迟操作
移除不必要的长延迟,只保留短延迟让Mail.app完成操作即可。
内容的提问来源于stack exchange,提问作者Stefan
相关产品推荐
相关产品推荐

