×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    46

    Thumbs up send mail from j2me application

    how to send mail from j2me application?

    try to give sample code for send mail.

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: send mail from j2me application

    Quote Originally Posted by kavitha@i-waves.com View Post
    how to send mail from j2me application?

    try to give sample code for send mail.
    This topic has already been discussed many times on this Forum, have a search here or even on the web, you will surely get some help.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    46

    Re: send mail from j2me application

    ya i got code from this link. http://www.java-email.com/content/view/14/33/
    This link using SMTP server to send mail.
    when i run this application it shows " " exception.Cannot connect to SMTP server. Ping the server to make sure it is running...

    i used following url for socket connection.

    private String smtpServerAddress="smtp.gmail.com";
    sc = (SocketConnection)
    Connector.open("socket://"+smtpServerAddress+":465");

    i dont know what wrong is in with my code.
    plz help me.

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: send mail from j2me application

    Quote Originally Posted by kavitha@i-waves.com View Post
    ya i got code from this link. http://www.java-email.com/content/view/14/33/
    This link using SMTP server to send mail.
    when i run this application it shows " " exception.Cannot connect to SMTP server. Ping the server to make sure it is running...

    i used following url for socket connection.

    private String smtpServerAddress="smtp.gmail.com";
    sc = (SocketConnection)
    Connector.open("socket://"+smtpServerAddress+":465");

    i dont know what wrong is in with my code.
    plz help me.
    is your server running, after reading the text above, I suspect that the server is not running , please check, and make the server up.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    46

    Re: send mail from j2me application

    how to use MailAPI for sending mail?

    i used mailAPI jar file in my application resource file.
    but when i run the application it always shows "Preverification failed with error code 1".
    how can i rectify this problem?

    how to use MailAPI package into j2me application?
    Is it possible or not?

  6. #6
    Registered User
    Join Date
    Aug 2010
    Posts
    46

    Re: send mail from j2me application

    hai R a j - The K e r n e l, please help me to do my task.

    i used mail4ME api for sending mail..........
    used code from this link http://wiki.forum.nokia.com/index.ph...e_applications

    attached my code in below

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    import de.trantor.mail.MailException;
    import de.trantor.mail.Message;
    import de.trantor.mail.SmtpClient;
    import de.trantor.mail.j2me.ConnectionImpl;
    //import de.trantor.mail.j2me.ConnectionImpl;
    //import de.trantor.mail.demo.j2me.MailMIDlet;
    import java.io.IOException;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.TextField;



    /**
    * @author Kavitha
    */
    public class JavaMail extends MIDlet implements CommandListener
    {
    Display display = null;
    // email form fields
    /* TextField toField = null;
    TextField subjectField = null;
    TextField msgField = null;
    static final Command sendCommand = new Command("send", Command.OK, 2);
    static final Command clearCommand = new Command("clear", Command.STOP, 3);
    String to;
    String subject;
    String msg;*/
    Form form;
    static final Command clearCommand = new Command("clear", Command.STOP, 3);
    static final Command sendCommand = new Command("send", Command.OK, 2);

    public JavaMail()
    {
    display = Display.getDisplay(this);
    form = new Form("Compose Message");
    /*toField = new TextField("To:", "", 25, TextField.EMAILADDR);
    subjectField = new TextField("Subject:", "", 15, TextField.ANY);
    msgField = new TextField("MsgBody:", "", 90, TextField.ANY);*/
    }

    public void startApp()
    {

    /*form.append(toField);
    form.append(subjectField);
    form.append(msgField);*/
    form.addCommand(clearCommand);
    form.addCommand(sendCommand);
    form.setCommandListener(this);
    display.setCurrent(form);
    }

    public void pauseApp()
    {
    }

    public void destroyApp(boolean unconditional)
    {
    // notifyDestroyed();
    }

    public void commandAction(Command c, Displayable d)
    {
    // throw new UnsupportedOperationException("Not supported yet.");
    String label = c.getLabel();
    if(label.equals("clear"))
    {
    // destroyApp(true);
    notifyDestroyed();
    }
    else if (label.equals("send"))
    {
    try{

    Message message = new Message("kavitharajdurai@gmail.com","keenkavi@gmail.com","hai");
    message.addBodyLine("haihaihaihai");

    SmtpClient smtpClient = null; // use proxy:
    //smtpClient = new SmtpClient( new de.trantor.mail.http.ConnectionImpl(httpHost, 8080), hostname);
    //String hostname="10.37.4.81";
    String hostname="i-waves.local";
    String smtpHost="smtp.gmail.com";
    String smtpUser="kavitharajdurai@gmail.com";
    String smtpPass="kavitha";
    smtpClient = new SmtpClient(hostname);
    try {
    smtpClient.open(smtpHost, 0, false, smtpUser, smtpPass);
    // smtpClient.open(smtpHost);
    } catch (IOException ex) {
    System.out.println("IOException in SMTP client opened");
    ex.printStackTrace();
    } catch (MailException ex) {
    System.out.println("MailException in SMTP client opened");
    ex.printStackTrace();
    }
    try {
    smtpClient.sendMessage(message);
    } catch (IOException ex) {
    System.out.println("IOException in SMTP client Message sending");
    ex.printStackTrace();
    } catch (MailException ex) {
    System.out.println("MailException in SMTP client Message sending");
    ex.printStackTrace();
    }
    smtpClient.close();
    }
    catch(Exception e)
    {
    System.out.println("cannot use mail4ME method");
    e.printStackTrace();
    }
    // notifyDestroyed();
    /* to = toField.getString();
    subject = subjectField.getString();
    msg = msgField.getString();
    EmailClient client = new EmailClient
    (this,"keenkavi@gmail.com", to, subject, msg);
    client.start();*/
    }
    }
    }



    but when i run this application following exception thrown...

    cannot use mail4ME method
    java.lang.StringIndexOutOfBoundsException
    at java.lang.String.substring(String.java:1938)
    at de.trantor.mail.Message.intToStr(), bci=19
    at de.trantor.mail.Message.getCanonicalDate(), bci=269
    at de.trantor.mail.Message.<init>(), bci=213
    at JavaMail.commandAction(JavaMail.java:90)
    at javax.microedition.lcdui.Display$ChameleonTunnel.callScreenListener(), bci=46
    at com.sun.midp.chameleon.layers.SoftButtonLayer.processCommand(), bci=74
    at com.sun.midp.chameleon.layers.SoftButtonLayer.soft2(), bci=173
    at com.sun.midp.chameleon.layers.SoftButtonLayer.keyInput(), bci=78
    at com.sun.midp.chameleon.CWindow.keyInput(), bci=38
    at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handleKeyEvent(), bci=17
    at com.sun.midp.lcdui.DisplayEventListener.process(), bci=277
    at com.sun.midp.events.EventQueue.run(), bci=179
    at java.lang.Thread.run(Thread.java:619)

    what fault occured in my code.

    is it possible to use mail4ME method for sending mail.
    please reply.
    Last edited by kavitha@i-waves.com; 2010-11-22 at 06:37. Reason: want to add more in this post

  7. #7
    Registered User
    Join Date
    Jul 2010
    Posts
    4

    Re: send mail from j2me application

    Hi , Kavitha

    I have successfully sent a mail.
    I also come to encounter same issue of StrinOutofbondIndex Exception.

    I found where the exception is encountered.

    While creating the code of Message object In your code that is


    Message message = new Message("kavitharajdurai@gmail.com","keenkavi@gmail.com","hai");

    comment above line replace with below code

    Create message object as fallowing

    Message message = new Message();
    message.setHeaderValue("From" , "kisna_kn@yahoo.co.in");
    message.setHeaderValue("To" , "kisna_kn@yahoo.co.in");

    try with above code . it may work.

  8. #8
    Registered User
    Join Date
    Aug 2010
    Posts
    13

    Re: send mail from j2me application

    hai thanks for ur valuable reply.
    i used above method. now string out of bound exception solved.
    now my problem is MailException in SMTP client opened .

    it shows following exception:

    de.trantor.mail.MailException: 530 5.7.0 Must issue a STARTTLS command first. q33sm6350059yba.19
    at de.trantor.mail.SmtpClient.execute(), bci=100
    at de.trantor.mail.SmtpClient.open(), bci=99
    at JavaMail.commandAction(JavaMail.java:110)
    at javax.microedition.lcdui.Display$ChameleonTunnel.callScreenListener(), bci=46
    at com.sun.midp.chameleon.layers.SoftButtonLayer.processCommand(), bci=74
    at com.sun.midp.chameleon.layers.SoftButtonLayer.soft2(), bci=173
    at com.sun.midp.chameleon.layers.SoftButtonLayer.keyInput(), bci=78
    at com.sun.midp.chameleon.CWindow.keyInput(), bci=38
    at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handleKeyEvent(), bci=17
    at com.sun.midp.lcdui.DisplayEventListener.process(), bci=277
    at com.sun.midp.events.EventQueue.run(), bci=179
    at java.lang.Thread.run(Thread.java:619)
    cannot use mail4ME method
    java.lang.NullPointerException: 0
    at de.trantor.mail.j2me.ConnectionImpl.write(), bci=7
    at de.trantor.mail.Connection.send(), bci=130
    at de.trantor.mail.SmtpClient.execute(), bci=9
    at de.trantor.mail.SmtpClient.sendMessage(), bci=31
    at de.trantor.mail.SmtpClient.sendMessage(), bci=10
    at JavaMail.commandAction(JavaMail.java:120)
    at javax.microedition.lcdui.Display$ChameleonTunnel.callScreenListener(), bci=46
    at com.sun.midp.chameleon.layers.SoftButtonLayer.processCommand(), bci=74
    at com.sun.midp.chameleon.layers.SoftButtonLayer.soft2(), bci=173
    at com.sun.midp.chameleon.layers.SoftButtonLayer.keyInput(), bci=78
    at com.sun.midp.chameleon.CWindow.keyInput(), bci=38
    at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handleKeyEvent(), bci=17
    at com.sun.midp.lcdui.DisplayEventListener.process(), bci=277
    at com.sun.midp.events.EventQueue.run(), bci=179
    at java.lang.Thread.run(Thread.java:619)


    i couldnt find y this exception thrown.

    If possible plz give ur sample code for send mail from j2me application by using this mail4ME api.

  9. #9
    Registered User
    Join Date
    Jul 2010
    Posts
    4

    Re: send mail from j2me application

    Hi, Kavitha

    Exception are throwing due to unauthorised SMTP Server access,

    because you are using Gmail SMTP Server .
    They might be not granting access.

    Try some other mail sever.

    The code is correct what you have used .
    The above exception occured in while sending message.
    So , try some other SMTP server. It is sure that you are able send mail.

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105

    Re: send mail from j2me application

    Quote Originally Posted by kavitharajdurai View Post
    de.trantor.mail.MailException: 530 5.7.0 Must issue a STARTTLS command first.
    StartTLS is not about authorization, but about using a secure connection, very much like HTTPS. If your library does not support StartTLS for SMTP on port 587 (or port 25), go for port 465 which requires a SecureConnection: ssl://smtp.googlemail.com:465
    However, if you did not understand that error message yourself, I recommend to read about SMTP first for example the RFCs or to get an overview a good book.
    Quote Originally Posted by kavitharajdurai View Post
    at JavaMail.commandAction(JavaMail.java:120)
    You call a method which might block. You do not know which thread you might block, because you start from within your CommandListener.commandAction. If you block the wrong thread like the EventDispatcher, the whole user interface might be blocked. Even worse, if you block the main thread, the whole MIDlet could block. Your coding style is very dangerous. Always, start a new thread from within your listener and execute the code there. Please read the whole MSA (JSR 248) specification for more tweaks and tricks like this.
    Last edited by traud; 2010-12-23 at 14:51.

  11. #11
    Registered User
    Join Date
    Aug 2010
    Posts
    13

    Re: send mail from j2me application

    hai thank u so much.
    i used smtp server for yahoo. now mail sent through j2me application.
    now my problem is its working fine in simulator. but in real device its not working. when i pressed send button there is no response. I checked this code in E-71 device.

    It shows following exception in device.
    de.trantor.mail.MailException: 421 service not available. closing transmission.

    i find this problem in open smtpclient. problem in ftp server log in.
    how to solve this problem?
    did u face this problem?

    Is this code working fine in ur real device???
    Last edited by kavitharajdurai; 2010-12-27 at 10:00. Reason: for want to add more information

  12. #12
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,553

    Re: send mail from j2me application

    On a real device, it may be that your mobile network operator is blocking SMTP access to SMTP servers that are not theirs (such as Yahoo!). Instead of Yahoo!, try using your operator's SMTP server. You can also try to see if there's a difference whether you use your operator's WAP access point vs. their GPRS Internet access point (or a Wi-Fi/WLAN access point, which is then not using your mobile network).

  13. #13
    Registered User
    Join Date
    Aug 2010
    Posts
    13

    Re: send mail from j2me application

    There is no problem in network side. Because we can send mail from real device browser. but when i try to send mail through application this exception occur. "de.trantor.mail.MailException: 421 service not available.Closing transmission."
    how to solve this exception.
    Try to give any solution for this please.

    also i tried to send with gmail smtp server. following exception occur.
    de.trantor.mail.MailException: 530 5.7.0 Must issue a STARTTLS command first. l26sm13514160icl.16
    at de.trantor.mail.SmtpClient.execute(), bci=100
    at de.trantor.mail.SmtpClient.open(), bci=99
    at JavaMail.run(JavaMail.java:154)
    at java.lang.Thread.run(), bci=11
    cannot use mail4ME method
    java.lang.NullPointerException: 0
    at de.trantor.mail.j2me.ConnectionImpl.write(), bci=7
    at de.trantor.mail.Connection.send(), bci=130
    at de.trantor.mail.SmtpClient.execute(), bci=9
    at de.trantor.mail.SmtpClient.sendMessage(), bci=31
    at de.trantor.mail.SmtpClient.sendMessage(), bci=10
    at JavaMail.run(JavaMail.java:173)
    at java.lang.Thread.run(), bci=11
    Uncaught exception: java.lang.IllegalArgumentException
    at javax.microedition.lcdui.Display.setCurrent(), bci=160

    How to issue STARTTLS command?

  14. #14
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105

    Re: send mail from j2me application

    Stay away from STARTTLS and use port 465 for SMTP. If you cannot do without STARTTLS, have a look at mujMail and how they do STARTTLS.

  15. #15
    Registered User
    Join Date
    Jan 2011
    Posts
    3

    Re: send mail from j2me application

    Hi ,

    i am using yahoo smtp server.
    I am facing the same problem as by kavithaa... my code is working on s40 emulator but it gives same error 421 service not available when test it on S60 emulator .

    same thing happend when try it on device which is again S60 v3 device (Nokia E50)..

    Hi petrib,
    Your reply to kavithaa :

    On a real device, it may be that your mobile network operator is blocking SMTP access to SMTP servers that are not theirs (such as Yahoo!).
    is there any way out to check if mobile network is blocking SMTP ....at same time if its working on S40 emulator any reasons it is not working on S60 emulator..does this mean it is some thing related to S60 & S40 difference
    as per my requirement i have to use yahoo smtp server only .
    Its a while that i am stuck in this error. please give some solution for this

    Thanks in advance

Similar Threads

  1. How to send sms through my j2me application
    By sandude7 in forum Mobile Java General
    Replies: 14
    Last Post: 2012-10-15, 11:12
  2. send mail from j2me device
    By kavitha@i-waves.com in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2010-09-07, 10:33
  3. can we send SMS using J2ME application ?????
    By anupam1107 in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2010-01-27, 11:37
  4. Using GPRS to send message through J2ME application
    By sandude7 in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2006-02-12, 14:12
  5. Replies: 1
    Last Post: 2005-12-15, 16:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×