File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sending email using /usr/bin/mail

 
lina ajay
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic