Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 880
Matt Avatar asked Jul 26 '26 21:07

Matt


1 Answers

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.

like image 160
regulus6633 Avatar answered Jul 29 '26 11:07

regulus6633



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!