aspose file tools*
The moose likes Java in General and the fly likes calling something like mailto from Java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "calling something like mailto from Java program" Watch "calling something like mailto from Java program" New topic
Author

calling something like mailto from Java program

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
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...
Tom Purl
Ranch Hand

Joined: May 24, 2002
Posts: 104
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.


Tom Purl<br />SCJP 1.4
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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 ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
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
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

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.


http://home.arcor.de/hirnstrom/bewerbung
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling something like mailto from Java program