使用AppleScript+CSV批量发邮件,iOS端邮件出现首行引用层级问题求助
解决Apple Mail脚本发送邮件首行引用缩进问题
问题现象
使用AppleScript结合Apple Mail给Excel中的联系人发送个性化邮件时,邮件在iOS及其他客户端显示首行带有引用层级(缩进)。
原因分析
Apple Mail默认会对纯文本内容进行格式解析,当内容的换行或开头格式符合邮件引用规则时,会被客户端识别为引用块,导致首行缩进。此外,直接设置content属性时,Mail可能会自动转换格式为富文本/HTML,引发排版异常。
解决方案
方法1:强制使用纯文本格式发送
在创建邮件后,明确设置邮件的内容类型为纯文本,避免自动格式转换:
修改后的核心代码:
repeat with i from 1 to count lastname tell application "Mail" activate set mymail to make new outgoing message at the beginning of outgoing messages with properties {subject:"subject"} tell mymail make new to recipient at beginning of to recipients with properties {address:item i of eAddress} -- 强制设置为纯文本格式 set content type to plain text set content to "Hi Dr. " & item i of lastname & "," & return & "Email Body" end tell set visible of mymail to true activate send mymail end tell end repeat
方法2:使用HTML格式内容
通过HTML精确控制邮件排版,彻底避免客户端自动解析引用的问题:
修改后的核心代码:
repeat with i from 1 to count lastname tell application "Mail" activate set mymail to make new outgoing message at the beginning of outgoing messages with properties {subject:"subject", content type:html} tell mymail make new to recipient at beginning of to recipients with properties {address:item i of eAddress} -- 使用HTML内容,确保排版可控 set content to "<p>Hi Dr. " & item i of lastname & ",</p><p>Email Body</p>" end tell set visible of mymail to true activate send mymail end tell end repeat
注意事项
- 原代码中
set content to "Hi Dr. " & lastname & ","存在逻辑错误,应该是item i of lastname(否则会把整个姓氏列表插入到每封邮件中),已在上述代码中修正。 - 使用HTML格式时,可以自由添加更多排版样式(如换行、段落、字体等),适配不同邮件客户端的显示效果。
内容的提问来源于stack exchange,提问作者Tyler
相关产品推荐
相关产品推荐

