使用 Java 在 Mac 上以编程方式发送电子邮件(通过 Mac 邮件客户端)

发布于 2024-11-09 04:05:38 字数 433 浏览 0 评论 0原文

我对这个问题做了很多研究,但似乎无法为我的问题提出可靠的解决方案。

我正在开发一个 Java 客户端应用程序,它(应该)允许用户从 Mac 地址簿中导入联系人,方法是以列表格式获取联系人,并允许用户选择一个子集/全部,然后单击一个按钮,将“邀请”发送到这些用户。

我能够使用 Rococoa Java 框架获取联系人,但我不确定如何发送电子邮件或者是否可能。我意识到这存在安全问题,但我能够在 Outlook for PC 上完成相同的任务。

看来我可能必须从 Java 调用 Applescript,手动打开 Mac 邮件客户端并使用其默认邮件帐户设置发送电子邮件。

我可能完全偏离了基地...我是否应该通过用户的默认邮件帐户发送邮件?我想避免使用不同的邮件服务器以避免垃圾邮件等。

任何帮助将不胜感激,感谢您的宝贵时间。

  • 马特

I've done quite a bit of research on this matter and I can't seem to come up with a solid solution to my problem.

I am developing a Java client application that (should) allow users to import their contacts from Mac Address Book by fetching them in a list format and allowing the user to select a subset/all and click a button that would send an "invitation" to these users.

I was able to grab contacts using the Rococoa Java framework but I am uncertain as to how to send email or if it is even possible. I realize there are security concerns with this, but I was able to accomplish this same task on Outlook for PC.

It seems that I may have to call an Applescript from my Java that manually opens Mac Mail Client and sends email using their default mail account setup.

I could be totally off-base here... should I even bother sending mail through the user's default Mail account? I wanted to avoid using a different mail server to avoid spam etc.

Any help would be appreciated, thank you for your time.

  • Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洛阳烟雨空心柳 2024-11-16 04:05:38

这是一个使用 Mail 的 applescript...

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。我制作了一个你可以使用的命令行程序。在此处找到它。有在网页上使用它的示例代码。

Here's an applescript to use 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

Another option, if you know the smtp information, is to use python. I made a command line program you can use. Find it here. There's example code to use it on the web page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文