Send mail through Java program. ERROR javax.mail.MessagingException: [EOF]

Hi,
i've a java Mail program which will send the mail thro smtp server.
when i try to execute this program im getting the error javax.mail.MessagingException: [EOF]
i've attached both code & error.
while running the program need to give the arguments
ex : java SendMail smtpserver frommailid tomailid subject body
please provide me the solution.
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class SendMail {
     public static void main(String[] args) {
          try
     String smtpServer=args[0];
     String to=args[1];
     String from=args[2];
     String subject=args[3];
     String body=args[4];
     send(smtpServer, to, from, subject, body);
     catch (Exception ex)
     System.out.println("Usage: java SendMail"
     +" smtpServer toAddress fromAddress subjectText bodyText");
     System.exit(0);
     public static void send(String smtpServer, String to, String from
               , String subject, String body)
               try
               Properties props = System.getProperties();
               props.put("mail.smtp.host", smtpServer);
               Session session = Session.getDefaultInstance(props, null);
               Message msg = new MimeMessage(session);
               msg.setFrom(new InternetAddress(from));
               msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to, false));
               msg.setSubject(subject);
               msg.setText(body);
               msg.setSentDate(new Date());
               System.out.println("test 1--");
               Transport.send(msg);
               System.out.println("test 2--");
               System.out.println("Message sent OK.");
               catch (Exception ex)
               ex.printStackTrace();
thanks for the help in advance.
regs
lal.

I ran into a similar error today. I fixed it by setting up SMTP authentication because my ISP's help pages said that they would allow only SMTP authentication.
Here is what I did:
Transport transport =
mailConnection.getTransport("smtp");
transport.connect(
"hostname", "email", "password");
Transport.send(msg);
I also passed the following property while creating the session:
props.put("mail.smtp.auth", "true");
finally turning on debug helped:
session.setDebug(true);
session.setDebugOut(null);
Hope this helps

Similar Messages

  • How to send sms through java program?

    hi,
    i am trying to send sms through java program.i am usining ubuntu 6.04.i am using modem MC35i.i use the jSMSEnjine.jar and rxtxcomm.jar.
    these are the following program.
    import org.jsmsengine.*;
    import java.util.*;
    class SendMessage
         public static void main(String[] args)
              int status;
              // Create jSMSEngine service.
         CService srv = new CService("Com2",9600);
              //CService srv = new CService("COM2",9600);
              System.out.println();
              System.out.println("SendMessage(): sample application.");
              System.out.println(" Using " + srv._name + " " + srv._version);
              System.out.println();
              try
                   //     Initialize service.     
                   srv.initialize();
                   Thread thread =Thread.currentThread();
                   thread.sleep(1000);
                   System.out.println(srv);
                   //     Set the cache directory.
                   srv.setCacheDir(".\\");
                   //     Set the phonebook.
                   //     srv.setPhoneBook("../misc/phonebook.xml");
                   //     Connect to GSM device.
                   status = srv.connect();
                   //     Did we connect ok?
                   int st=CService.ERR_OK;
                   System.out.println(st);
                   System.out.println(status);
                   if (status == CService.ERR_OK)
                        //     Set the operation mode to PDU - default is ASCII.
                        srv.setOperationMode(CService.MODE_PDU);
                        // Set the SMSC number (set to default).
                        srv.setSmscNumber("");
                        //     Print out GSM device info...
                        System.out.println("Mobile Device Information: ");
                        System.out.println("     Manufacturer : " + srv.getDeviceInfo().getManufacturer());
                        System.out.println("     Model : " + srv.getDeviceInfo().getModel());
                        System.out.println("     Serial No : " + srv.getDeviceInfo().getSerialNo());
                        System.out.println("     IMSI : " + srv.getDeviceInfo().getImsi());
                        System.out.println("     S/W Version : " + srv.getDeviceInfo().getSwVersion());
                        System.out.println("     Battery Level : " + srv.getDeviceInfo().getBatteryLevel() + "%");
                        System.out.println("     Signal Level : " + srv.getDeviceInfo().getSignalLevel() + "%");
                        //     Create a COutgoingMessage object and dispatch it.
                        //     *** Please update the phone number with one of your choice ***
    // String smsLengthTest="Hi"+"\nTesting is going on.Test for sending unlimited number of charecter.So you will get N number of SMS.Initially I trancate the whole string by 70 charecter.Later I will put it upto 90 charecter.Some chararecter should kept for header portion.I don't know the total number.It is just test.If you got the sms u should appreciate me...This is Ripon...I have written sms program";
    String smsLengthTest="Hi\n"+"This is Govindo";
    int mao=smsLengthTest.length();
    System.out.println("Length of sms :"+mao);
    String smsNo="9433314095";
    smsNo="+91"+smsNo;
    if(mao<70)
    COutgoingMessage msg = new COutgoingMessage(smsNo,smsLengthTest);
    //     Character set is 7bit by default - lets make it UNICODE :)
    //     We can do this, because we are in PDU mode (look at line 63). When in ASCII mode,
    //          this does not make ANY difference...
    msg.setMessageEncoding(CMessage.MESSAGE_ENCODING_UNICODE);
    if (srv.sendMessage(msg) == CService.ERR_OK) System.out.println("Message Sent!");
    else System.out.println("Message Failed!");
    else
    // COutgoingMessage msg = new COutgoingMessage(smsNo,smsLengthTest);
    // LinkedList messageList;
    // messageList = new LinkedList();
    // messageList.add(msg);
    // LinkedList maooo=new LinkedList();
    // maooo=srv.splitLargeMessages(messageList);
    int sizelength=0;
    int counter=0;
    sizelength=smsLengthTest.length();
    System.out.println("SMS length :"+sizelength);
    int smsCntr=sizelength/70;
    System.out.println("smsCntr :"+smsCntr);
    counter=smsCntr+1;
    int j=70;
    int k=0;
    try
    for(int i=0;i<smsCntr;i++)
    String test="";
    test=test+i;
    test=smsLengthTest.substring(k,j);
    System.out.println(test);
    System.out.println(test.length());
    COutgoingMessage msg = new COutgoingMessage(smsNo, test);
    System.out.println("hi this is suman" + smsNo);
    //     Character set is 7bit by default - lets make it UNICODE :)
    //     We can do this, because we are in PDU mode (look at line 63). When in ASCII mode,
    //          this does not make ANY difference...
    msg.setMessageEncoding(CMessage.MESSAGE_ENCODING_UNICODE);
    if (srv.sendMessage(msg) == CService.ERR_OK) System.out.println("Message Sent!");
    else System.out.println("Message Failed!");
    k=k+70;
    j=j+70;
    catch(Exception e)
    System.out.println("Error...1");
    e.printStackTrace();
    e.getMessage();
    String lastPortion=smsLengthTest.substring(k);
    System.out.println(lastPortion);
    COutgoingMessage msg = new COutgoingMessage(smsNo, lastPortion);
    //     Character set is 7bit by default - lets make it UNICODE :)
    //     We can do this, because we are in PDU mode (look at line 63). When in ASCII mode,
    //          this does not make ANY difference...
    msg.setMessageEncoding(CMessage.MESSAGE_ENCODING_UNICODE);
    if (srv.sendMessage(msg) == CService.ERR_OK) System.out.println("Message Sent!");
    else System.out.println("Message Failed!");
                        // Disconnect from GSM device.
                        srv.disconnect();
                   else System.out.println("Connection to mobile failed, error: " + status);
              catch (Exception e)
                   e.printStackTrace();
              System.exit(0);
    the error is:
    SendMessage(): sample application.
    Using jSMSEngine API 1.2.6 (B1)
    org.jsmsengine.CService@addbf1
    0
    -101
    Connection to mobile failed, error: -101
    please help me,its very urgent.

    come back in about 5 years, we may have time for you by then.
    In the meantime, how about contacting the people who wrote that library and asking them nicely for help (rather than trying to order people to drop whatever they're doing and jump through hoops to accommodate your every wish as you're doing here)?

  • Exception in thread "main" javax.mail.MessagingException: [EOF]

    hi i have a new Application which i need to send Email from it to people
    i have tried the code in my university pc's and i works soo fine...but in my home
    it gave my error
    here is the code
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    public class TestMail
         public static void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
             boolean debug = false;
              //Set the host smtp address
              Properties props = new Properties();
              props.put("mail.smtp.host", "mx2.hotmail.com");
             // create some properties and get the default Session
             Session session = Session.getDefaultInstance(props, null);
             session.setDebug(debug);
             // create a message
                  Message msg = new MimeMessage(session);
             // set the from and to address
             InternetAddress addressFrom = new InternetAddress(from);
             msg.setFrom(addressFrom);
             InternetAddress[] addressTo = new InternetAddress[recipients.length];
             for (int i = 0; i < recipients.length; i++)
                 addressTo[i] = new InternetAddress(recipients);
         msg.setRecipients(Message.RecipientType.TO, addressTo);
         // Optional : You can also set your custom headers in the Email if you Want
         msg.addHeader("MyHeaderName", "myHeaderValue");
         // Setting the Subject and Content Type
         msg.setSubject(subject);
         msg.setContent(message, "text/plain");
         Transport.send(msg);
         public static void main(String args[])throws MessagingException
              String mailers[] = new String[1];
              mailers[0] = "[email protected]";
              postMail(mailers,"hello","hello my dear ay","[email protected]");
    }and  here is the output of the programe(the error)Exception in thread "main" javax.mail.MessagingException: [EOF]
    at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1
    512)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
    at javax.mail.Transport.send0(Transport.java:189)
    at javax.mail.Transport.send(Transport.java:118)
    at TestMail.postMail(TestMail.java:39)
    at TestMail.main(TestMail.java:45)
    Press any key to continue . . .plz help meee
    Edited by: mld on Dec 30, 2007 9:37 AM
    Edited by: mld on Dec 31, 2007 2:32 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    i have tried every thing
    i put stmp.bebug in my code and it gave me the following (tis is a part of the output...the other is not important)
    DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
    DEBUG: !anyLoaded
    DEBUG: not loading resource: /META-INF/javamail.address.map
    DEBUG: not loading file: C:\Program Files\Java\jdk1.5.0_06\jre\lib\javamail.addr
    ess.map
    DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.5.0_06\jre\lib\
    javamail.address.map (The system cannot find the file specified)
    Exception in thread "main" javax.mail.MessagingException: [EOF]
            at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
            at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1
    512)
            at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
            at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
            at javax.mail.Transport.send0(Transport.java:189)
            at javax.mail.Transport.send(Transport.java:118)
            at TestMail.postMail(TestMail.java:43)
            at TestMail.main(TestMail.java:49)
    Press any key to continue . . .

  • Accessing RUN through java programming

    Sir,
    i need to develop a java application t access "run" in start menu.How can i access the run menu through java programming.?I want to run the program in the run command when we input command through the java program..please help me..if you have the code palese send it tio me please..........

    But I cant access the drives for eg: I wrote c:\programfiles as input but i got an exception like this
    error=3
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)
    at java.lang.Runtime.exec(Runtime.java:591)
    at java.lang.Runtime.exec(Runtime.java:429)
    at java.lang.Runtime.exec(Runtime.java:326)
    at ex.main(ex.java:10)
    how can correct this error...

  • How to store xml data into file in xml format through java program?

    HI Friends,
    Please let me know
    How to store xml data into file in xml format through java program?
    thanks......
    can discuss further at messenger.....
    Avanish Kumar Singh
    Software Engineer,
    Samsung India Development Center,
    Bangalore--560001.
    [email protected]

    Hi i need to write the data from an XML file to a Microsoft SQL SErver database!
    i got a piece of code from the net which allows me to parse th file:
    import java.io.IOException;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    import org.apache.xerces.parsers.SAXParser;
    import java.lang.*;
    public class MySaxParser extends DefaultHandler
    private static int INDENT = 4;
    private static String attList = "";
    public static void main(String[] argv)
    if (argv.length != 1)
    System.out.println("Usage: java MySaxParser [URI]");
    System.exit(0);
    String uri = argv[0];
    try
    XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    MySaxParser MySaxParserInstance = new MySaxParser();
    parser.setContentHandler(MySaxParserInstance);
    parser.parse(uri);
    catch(IOException ioe)
    ioe.printStackTrace();
    catch(SAXException saxe)
    saxe.printStackTrace();
    private int idx = 0;
    public void characters(char[] ch, int start, int length)
    throws SAXException
    String s = new String(ch, start, length);
    if (ch[0] == '\n')
    return;
    System.out.println(getIndent() + " Value: " + s);
    public void endDocument() throws SAXException
    idx -= INDENT;
    public void endElement(String uri, String localName, String qName) throws SAXException
    if (!attList.equals(""))
    System.out.println(getIndent() + " Attributes: " + attList);
    attList = "";
    System.out.println(getIndent() + "end document");
    idx -= INDENT;
    public void startDocument() throws SAXException
    idx += INDENT;
    public void startElement(String uri,
    String localName,
    String qName,
    Attributes attributes) throws SAXException
    idx += INDENT;
    System.out.println('\n' + getIndent() + "start element: " + localName);
    if (localName.compareTo("Machine") == 0)
    System.out.println("YES");
    if (attributes.getLength() > 0)
    idx += INDENT;
    for (int i = 0; i < attributes.getLength(); i++)
    attList = attList + attributes.getLocalName(i) + " = " + attributes.getValue(i);
    if (i < (attributes.getLength() - 1))
    attList = attList + ", ";
    idx-= INDENT;
    private String getIndent()
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < idx; i++)
    sb.append(" ");
    return sb.toString();
    }// END PRGM
    Now , am not a very good Java DEv. and i need to find a soln. to this prob within 1 week.
    The next step is to write the data to the DB.
    Am sending an example of my file:
    <Start>
    <Machine>
    <Hostname> IPCServer </Hostname>
    <HostID> 80c04499 </HostID>
    <MachineType> sun4u [ID 466748 kern.info] Sun Ultra 5/10 UPA/PCI (UltraSPARC-IIi 360MHz) </MachineType>
    <CPU> UltraSPARC-IIi at 360 MHz </CPU>
    <Memory> RAM : 512 MB </Memory>
    <HostAdapter>
    <HA> kern.info] </HA>
    </HostAdapter>
    <Harddisks>
    <HD>
    <HD1> c0t0d0 ctrl kern.info] target 0 lun 0 </HD1>
    <HD2> ST38420A 8.2 GB </HD2>
    </HD>
    </Harddisks>
    <GraphicCard> m64B : PCI PGX 8-bit +Accel. </GraphicCard>
    <NetworkType> hme0 : Fast-Ethernet </NetworkType>
    <EthernetAddress> 09:00:30:C1:34:90 </EthernetAddress>
    <IPAddress> 149.51.23.140 </IPAddress>
    </Machine>
    </Start>
    Note that i can have more than 1 machines (meaning that i have to loop thru the file to be able to write to the DB)
    Cal u tellme what to do!
    Even better- do u have a piece of code that will help me understand and implement the database writing portion?
    I badly need help here.
    THANX

  • Registrykey access through java program

    hi,i need help in accessing the registrykey entries made by the any software installed in the system through java program...pls send sample source code to [email protected]

    have you tried Runtime.getRuntime.exec("cmd /c start telnet");or someting like that?

  • How to change system time through java program

    Hi
    I want to know, how to change system time through java program.
    give me a idia with example.
    Thanks

    There isn't any core Java API for this. Use JNI or call an external process with Runtime.exec().
    ~

  • How to compile dunamically genrated java files through java program?

    Hi, I have a requirement where i generate java files from WSDL dynamically using wsdl2java jaxbri. I need to compile these files dynamically on the fly and jar it. Everything should happen through java program. Bcos everything is dynamic here, no information is known (like dir, file names ...) until the runtime. Everything is user fed.
    the directories may contain other directories with java files. its recursive
    i tried com.sun.tools.javac.Main.. but either its not scaling to my needs or i donno how to wok with this.
    is there any option to compile the java files as they are created thru JAXBRI (wsdl2java)?
    any help is appreciated..
    -s

    my requirement is :
    i create java files from wsdl2java (axis).. i need to compile all the java files.. directories with in the directories (recursive)...
    as bcos the the java files have inter-dependencies they have to be compiled as a bunch something like (java *.java). I donno how to do this in javac.Main tool
    Once all these files are compiled i need to create a jar out of them
    Any help is appreciated!

  • Opening Default TextEditor Independent of OS through Java Program

    Hi All,
    I need a small help, I have a requirement in my program. I need to open default Text Editor of OS through Java Program independent of OS.Now i am using java 5.0. Is this facility available in java 5.0 API or I have to use any third party API is required, if yes then please suggest�
    I apologize for my poor English...
    Thanks in Advance�
    RamaDevi B.

    The concept of a default text editor is not OS-independent. Linux doesn't have one. (Yes, a shell can have one via the EDITOR environment variable, but you can invoke a jar from a window manager's desktop without running a shell. Nor does mailcap really count, because that defines a text viewer rather than a text editor). As far as I'm aware, OS X doesn't have one. In fact, Windows is the only OS which I know to have one.

  • How to create an Oracle DATABASE through Java Programming Language.. ?

    How to create an Oracle DATABASE through Java Programming Language.. ?

    Oracle database administrators tend to be control freaks, especially in financial institutions where security is paramount.
    In general, they will supply you with a database, but require you to supply all the DDL scripts to create tables, indexes, views etc.
    So a certain amount of manual installation will always be required.
    Typically you would supply the SQL scripts, and a detailled installation document too.
    regards,
    Owen

  • Is it possible to send SMS through java

    Hi all
    I m a student and as a part of my project I need to create an SMS server(SMS gateway). Can we send SMS through Java and if yes then send me the code for the same . Also on which GSM Modem will it Work , I've heard about Nokia GSM Modem N32. Kindly Guide me regarding the Same.
    Regards
    MoComp

    Hi all
    I m a student and as a part of my project I need to
    create an SMS server(SMS gateway). Can we send SMSSo YOU need to write it.
    through Java and if yes then send me the code for theIt's possible, as there are several commercial offerings out there.
    But as YOU need to write it it won't do for you to try and trick someone else into writing it so you can submit it as your own.
    same . Also on which GSM Modem will it Work , I've
    heard about Nokia GSM Modem N32. Kindly Guide me
    regarding the Same.All depends on how you implement it.
    A real server would have its own hardware and software to pipe directly into the network of a telco, and a contract with that telco to use their network to send messages.

  • SLD - import and Export through Java Program

    Hi Exports,
    Can you please guide how we can do SLD import and export through java program? additionally wanted to export Landscape(technical system,Landscape,business system),software catalog(products,s/w components),Development(Name Reservation)
    Note: Manually we are doing through  http://<server host>:<port>/sld and navigate into administration-->import and Export
    Regards,
    Manivannan P

    closed

  • Setting java runtime option through java program

    I want to set java runtime options(like -verbose, -ea) through java program instead of setting them through command promt. (Like, I can set -D options through System.setProperty() method). Is there any way out?

    I want to set java runtime options(like -verbose,
    -ea) through java program instead of setting them
    through command promt. (Like, I can set -D options
    through System.setProperty() method). Is there any
    way out?I don't think you can (at least not for the Sun JVM).
    The command-line options for the JVM are used when the
    JVM is created, which precedes the loading of the class
    files representing your application. At that time it is too
    late to set the start-up options for the JVM which is already
    up and running.

  • How to send SMS from Java program?

    Hello,
    I want to know, how can I send SMS from Java program.I dont have any idea about SMS gateways. Can any one give me Sample code for sending the SMSs from Java Program.
    Thanks,
    -BR

    hi,
    refer javamail concepts
    http://www.google.co.in/search?q=javamail+simple+example&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

  • Changing the ip address of the local machine through java program

    Hi all,
    I want to change the ip address of the machine in windows and linux through java program. Iam not aware that wheather this is possible or not. If possible pls help me.
    Regards
    Bhaskar

    I'm always surprised by the weird things that developers find they need to do!

Maybe you are looking for

  • Dynamic Data Driven Color in Chart

    Post Author: csmith CA Forum: Charts and Graphs I am working on a report which needs to produce approx. 100 charts.  One of the requirements is to dynamically color the bars of the chart (alerts) dynamically based upon a field in the database.  The l

  • Import package failed

    hi When compiled with java 1.5, I get the message package a.b.c does not exist. Into what directory do you need to store a executalbe jar file in order to be able to import the package?

  • INVALID COULMN NAME EXCEPTION

    hi! again got struck with small thing.i am inserting record in a table using prepare statement. exception it shows is: exceptionjava.sql.SQLException: [Microsoft][ODBC driver for Oracle][Oracle]ORA-00904: invalid column name have look at the followin

  • Taking a long(ish) time to Sleep

    I wonder if anybody can shed any light on this recently occuring problem.  Up until a couple of days ago my iMac (Intel i3) would "sleep" almost immediately after selecting sleep from the menu bar. Now for some reason it takes about 30 seconds from s

  • Is there a newer version of iPlanet than 7.0.12?

    I could see some release notes about iPlanet release 7.0.13 as part of the Jan CPU released on 1/17, but i am not able to find where i can download the newer version? Any guidance will be helpful, thanks in advance.