• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calling something like mailto from Java program

 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing a batch file on Win 2000, and in the middle of it I'd like to launch a Java application that checks some stuff on my system and sends me an email if there's a problem. What's the simplest way to send a no-frills email in the middle of my program? Is it possible? Is there anything available like mailto in Unix? It seems like JavaMail might provide something, but that seems like a big API for writing entire mail applications, and all I want to do is something simple. Please excuse my ignorance about email stuff...
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know much about the JavaMail API, but I have worked with the other stuff.
You have two options in the Windows world. If this program is running on a machine that has IIS, then your machine has a mail server already installed. To invoke it, you can write a VBScript program that uses the MAPI API. This is the hard way, but it may be one of your limited options if you're running your program on a server that doesn't have MS Office installed on it.
The easier way is possible if you do have MS Outlook installed on your machine. Then you can write a fairly simple VBScript program that uses the Outlook object to send e-mails to people. There are dozens of tutorials on how to do this available on the web.
I really don't think that there are any sendmail-like, command-line email solutions for Windows unless you're willing to purchase third-party software. It's too bad that MS expects you to be a C++ or VB programmer to do anything even slightly complex on their OS.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although the JavaMail API isn't completely trivial, it's not very difficult either. There're examples in this forum for you to follow.
hth,
bear
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's something that works. I probably cut & pasted it from somewhere on the web. It imports from javax.mail and javax.mail.internet

[ August 08, 2003: Message edited by: Stan James ]
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks great...in my particular case I was able to get by with doing this:
http://forum.java.sun.com/thread.jsp?forum=31&thread=431872&start=0&range=15#1932569
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stephen Huey:
I'm writing a batch file on Win 2000, and in the middle of it I'd like to launch a Java application that checks some stuff on my system and sends me an email if there's a problem. What's the simplest way to send a no-frills email in the middle of my program?


If you're looking for a solution, you might think about ant.
Ant is free available, might be useful for other tasks too, and it would be easy to call ant from your batchfile.
Since Ant is written in Java, you could try to implement your own mailcommands and just learn from them.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, that URL solution is slick. Must use your default mail client, just like clicking a mailto link on a web page? We're a Lotus Notes shop with no SMTP client installed or servers around, so mailto links go nowhere. If you're producing this for distribution to strangers, you might want to take that into account. If it's just for you, Do The Simplest Thing That Can Possibly Work.
BTW: If this is just one step in a Windows batch process, look into Windows Scripting Host instead. You can replace the horrible batch language with VBScript or JScript:
Scripting: http://msdn.microsoft.com/library/default.asp?url=/nhp/default.asp?contentid=28001169
Messaging: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_cdo_queue_top.asp
[ August 08, 2003: Message edited by: Stan James ]
 
No holds barred. And no bars holed. Except this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic