在Mac上使用Java通过Mac以编程方式发送电子邮件通过Mac Mail Client

问题描述

|| 我已经在此问题上进行了大量研究,但似乎无法为我的问题提供可靠的解决方案。 我正在开发一个Java客户端应用程序,该程序(应)允许用户通过以列表格式提取联系人并允许其选择一个子集/全部并单击发送“邀请”的按钮来从Mac地址簿中导入他们的联系人。这些用户。 我可以使用rococoa Java框架来获取联系人,但是我不确定如何发送电子邮件或什至可以发送电子邮件。我意识到与此有关的安全性问题,但是我能够在Outlook for PC上完成相同的任务。 似乎我可能必须从Java调用Applescript,以手动打开Mac Mail Client并使用其邮件帐户设置发送电子邮件。 我在这里可能完全不在基地...我是否还要打扰通过用户邮件帐户发送邮件?我想避免使用其他邮件服务器来避免垃圾邮件等。 任何帮助将不胜感激,谢谢您的时间。 马特     

解决方法

这是使用Mail的小程序...
set emailSender to \"[email protected]>\"
set emailTo to \"[email protected]\"
set theSubject to \"The subject of the mail\"
set theContent to \"message body\"

tell application \"Mail\"
    set newMessage to make new outgoing message with properties {sender:emailSender,subject:theSubject,content:theContent,visible:true}
    tell newMessage
        make new to recipient at end of to recipients with properties {address:emailTo}
        send
    end tell
end tell
如果您知道smtp信息,另一种选择是使用python。我做了一个可以使用的命令行程序。在这里找到。在网页上有使用它的示例代码。