how to send mail from j2me application?
try to give sample code for send mail.
how to send mail from j2me application?
try to give sample code for send mail.
Thanks with Regards,
R a j - The K e r n e l
Join Delhi-NCR Nokia Developer's Community,
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.
Thanks with Regards,
R a j - The K e r n e l
Join Delhi-NCR Nokia Developer's Community,
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?
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
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.
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.
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.
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.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.
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
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).
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?
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.
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 :
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 differenceOn 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!).
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