hi,
I want to send an email using servlets.
I had tried some of the example codes from internet but didn't get any success.
i am j2me person and new in Servlets .
any suggestions please!
Thanks in advance
bhagya hari
Greenhorn
Joined: Oct 15, 2008
Posts: 5
posted
0
Please post what you have tried and the problem you have faced while running the code.
It will be helpful to fix the problems in your code.
firstName SecondName
Greenhorn
Joined: Mar 20, 2009
Posts: 15
posted
0
Here is the code which i got from internet but it is not sending email!
This is my servlet code
/* This method form Mail and send to server*/
private void sendMail(String server, String user,
String pwd, String address, String content) throws Exception {
try {
c = (StreamConnection)Connector.open(url, Connector.READ_WRITE);
is = c.openInputStream();
int ch;
sb = new StringBuffer();
while ((ch = is.read()) != -1) {
sb.append((char)ch);
}
} catch(Exception ex){ err = ex.getMessage(); } finally {
try {
if(is!= null) {is.close(); }
if(c != null) {c.close(); }
} catch(Exception exp) { err = exp.getMessage(); }
}
if (err == null) {
user = sb.toString();
if (user.indexOf("INVALIDUSR") >= 0) {
user = null;
showAlert("Invalid User Name and Password");
} else {
input = null;
dmenu = null;
displayMenu();
}
} else
showAlert(err); // Need to Show Error Page
}
private void showAlert(String err) {
Alert a = new Alert("Alert");
a.setString(err);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a);
}
private void handleMainMenu() {
int index = dmenu.getSelectedIndex();
switch(index) {
case 0 :
status = 1;
//loginUser();
break;
case 1 :
sendeMail();
break;
}
}
/* This method ask user to compose the message*/
private void sendeMail() {
Form menu = new Form("Send Message");
to = new TextField("Enter Reciepent :", "", 50, TextField.EMAILADDR);
msg = new TextField("Enter Message :", "", 250, TextField.ANY);
menu.append(to);
menu.append(msg);
menu.addCommand(okCommand);
menu.addCommand(exitCommand);
menu.setCommandListener(this);
display.setCurrent(menu);
}