f



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

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
+"'abc.xyz@gmail.com'");
}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'amita.chouhan@hewitt.com' error=2

0
1/4/2007 2:54:28 PM
comp.lang.java.programmer 52711 articles. 1 followers. Post Follow

3 Replies
1568 Views

Similar Articles

[PageSpeed] 57

> Process proc;
> proc = Runtime.getRuntime().exec("mailx -s "+ msg
> +"'abc.xyz@gmail.com'");
> }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'amita.chouhan@hewitt.com' 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

0
1/4/2007 7:21:19 PM
aemi wrote:

> 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
> +"'abc.xyz@gmail.com'");
> }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'amita.chouhan@hewitt.com' 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,
"abc.xyz@gmail.com"});



-- 
Nigel Wade, System Administrator, Space Plasma Physics Group,
            University of Leicester, Leicester, LE1 7RH, UK 
E-mail :    nmw@ion.le.ac.uk 
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555
0
nmw (873)
1/5/2007 2:40:23 PM
"aemi" <amita.chouhan@gmail.com> wrote in news:1167922468.283384.53170@
51g2000cwl.googlegroups.com:

> 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            gregb+usenet200612@blackholio.dyndns.org

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------
0
1/7/2007 4:50:54 PM
Reply: