Sending email programmatically on a Mac using Java (via Mac Mail Client)

I have done a lot of research on this, and I can’t find a solid solution to my problem.

I am developing a Java client application that (should) allow them to import their contacts from the Mac address book, selecting them in a list format and allowing the user to select a subset / all and press a button that will send an “invitation” to these users.

I managed to capture contacts using the Java Rococoa platform, but I'm not sure how to send emails, or if possible. I understand that there are security issues, but I was able to complete the same task in Outlook for PC.

It seems I might have to call Applescript from my Java, which manually opens the Mac Mail Client and sends email using its default account setting.

I could be completely out of the database here ... should I even send mail through my default Mail account? I wanted to avoid using another mail server to avoid spam, etc.

Any help would be appreciated, thanks for your time.

  • Matt
+3
source share
1 answer

Here is a box for using mail ...

set emailSender to "sender@email.com>"
set emailTo to "recipient@email.com"
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. , . . , -.

+2

All Articles