aspose file tools*
The moose likes Java in General and the fly likes Sending email using  /usr/bin/mail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sending email using  /usr/bin/mail" Watch "Sending email using  /usr/bin/mail" New topic
Author

Sending email using /usr/bin/mail

lina ajay
Ranch Hand

Joined: Apr 04, 2008
Posts: 31
Hi,
I am getting an exception while trying to send an email. I am executing it from my local workspace.

This is the code that I am using

Runtime rt = Runtime.getRuntime();
int rc = 0;
try {
Process p = rt.exec(new String[] { "/usr/bin/mail", "-s", Subject, tempmaillist });
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
bw.write(voidMessage);
..
..
bw.close();

p.waitFor();
rc = p.exitValue();
p.destroy();
} catch (Exception e) {
..
..
}
As soon as I execute (in debug mode) Process p = rt.exec(new String[] { "/usr/bin/mail", "-s", Subject, tempmaillist }); an exception is thrown

CreateProcess: /usr/bin/mail -s "Invalid data. Check the data" error=3

Can anybody please let me know what the problem could be.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

Sorry, I don't have a solution for your problem.

A better and platform-independent way to send e-mail from a Java program is by using the JavaMail API, instead of calling a native executable as you are doing now.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8705
    
    6

Your code works fine for me. Like the error message states, the data you are sending the process probably has problems.
As Jesper says, the JavaMail API is probably a better solution.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
 
subject: Sending email using /usr/bin/mail
 
Similar Threads
getRuntime question
getRuntime().exec() - HELP PLEASE
to call the mail message window of MS Outlook
Shell script from a java application
Opening CSV file in ReadOnly while writing data to it