I want to send a mail using mailx(unix) in java code

A

aemi

Hi All,

I am trying to send a mail using shell script as for that java will be
a bit bulkier , so I Am using mailx command of unix
..
..
..
..
..
------previous code----
..
..
..
Process proc;
proc = Runtime.getRuntime().exec("mailx -s "+ msg
+"'(e-mail address removed)'");
}catch(IOException e)
{System.out.println(" Error Occured "+e);}

is there anything wrong with this coz I am getting

an error msg like

Error Occured java.io.IOException: CreateProcess: mailx -s Mismatch
occured'(e-mail address removed)' error=2
 
M

Manish Pandit

Process proc;
proc = Runtime.getRuntime().exec("mailx -s "+ msg
+"'(e-mail address removed)'");
}catch(IOException e)
{System.out.println(" Error Occured "+e);}

is there anything wrong with this coz I am getting

an error msg like

Error Occured java.io.IOException: CreateProcess: mailx -s Mismatch
occured'(e-mail address removed)' error=2

Try using the other Runtime.exec method - the one that takes an array
of arguments.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#exec(java.lang.String[])

-cheers,
Manish
 
N

Nigel Wade

aemi said:
Hi All,

I am trying to send a mail using shell script as for that java will be
a bit bulkier , so I Am using mailx command of unix
.
.
.
.
.
------previous code----
.
.
.
Process proc;
proc = Runtime.getRuntime().exec("mailx -s "+ msg
+"'(e-mail address removed)'");
}catch(IOException e)
{System.out.println(" Error Occured "+e);}

is there anything wrong with this coz I am getting

an error msg like

Error Occured java.io.IOException: CreateProcess: mailx -s Mismatch
occured'(e-mail address removed)' error=2

Are you intending to send the entire "message" as the subject? That's what you
are doing. You are also assuming that mailx is on the current path.

You have not enclosed the subject in quotes on the command line, the -s flag
only accepts a single argument so everything else is taken to be a list of
recipients, and you have left no space between the subject and the recipient so
the actual recipient is being prefixed by the final word in the subject. You
would eliminate these problems if you use the Runtime.exec(String[]) method
i.e:
Runtime.getRuntime.exec(new String[] { "mailx", "-s", msg,
"(e-mail address removed)"});
 
G

Greg R. Broderick

I am trying to send a mail using shell script as for that java will be
a bit bulkier , so I Am using mailx command of unix

Use JavaMail instead, that way your code will work on multiple platforms and
will give you a lot more control over the mail that you send.

See <http://java.sun.com/products/javamail/downloads/index.html>.

Cheers
GRB

--
---------------------------------------------------------------------
Greg R. Broderick (e-mail address removed)

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top