Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh


Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends

Can you help me to send sms using a j2me application.

I have developed a j2me application which asks for input from the user. Then it assembles the input from the user for a specific message format.

What i need is this message should be sent to a specific mobile number. I think to send this message using an sms. But i dont know what happens when we send an sms. Whether a socket listning for the sms at the provider or etc

Can you help me to implemt this scenario.
Posts: 3281
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

This is a topic that has been discussed many times at Javaranch, it's usually a good idea to SearchFirst before posting

Please do post here again if you have any further questions though!
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI. You can try this code.

The following example uses Sun Microsystem�s JavaMail package to implement SMTP.
�Download Example Source Code
�Download Sun Microsystem Java Mail (mail.jar)
�Download Sun Microsystem Java Beans Activation Framework (activation.jar)

// Package Imports
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

// Public Class
public class EmailSMS {

// Global Variables
String TO;
String FROM;
String TEXT;

// Main function executed
public static void main(String[] args) throws Exception {
EmailSMS SMS = new EmailSMS();

SMS.setText("Hello World!");
boolean ret = SMS.send();

if (ret) {
System.out.println("SMS was sent!");
} else {
System.out.println("SMS was not sent - " + SMS.getLastError());

// Public Constructor
public EmailSMS() {
TO = null;
FROM = null;
SUBJECT = null;
TEXT = null;
MAILHOST = null;
LASTERROR = "No method called.";

public void setTo(String to) {
TO = to;

public String getTo() {
return TO;

public void setFrom(String from) {
FROM = from;

public String getFrom() {
return FROM;

public void setSubject(String subject) {
SUBJECT = subject;

public String getSubject() {
return SUBJECT;

public void setText(String text) {
TEXT = text;

public String getText() {
return TEXT;

public void setMailHost(String host) {
MAILHOST = host;

public String getMailHost() {
return MAILHOST;

public String getLastError() {

// Will attempt to send the Email SMS and return a boolean meaning it
// either failed or succeeded.
public boolean send() {

// Variables to check message length.
int maxLength;
int msgLength;

// Check to make sure that the parameters are correct
if (TO.indexOf("") > 0) {
maxLength = 140;
} else if (TO.indexOf("") > 0) {
maxLength = 280;
} else if (TO.indexOf("") > 0) {
maxLength = 100;
} else {
maxLength = 160;

// Calculate message length
msgLength = FROM.length() + 1 + SUBJECT.length() + 1 + TEXT.length();

// Typically, there are at least two characters of delimiter
// between the from, subject, and text. This is here to make
// sure the message isn't longer than the device supports.
if (msgLength > maxLength) {
LASTERROR = "SMS length too long.";
return false;

// Set Email Properties
Properties props = System.getProperties();

if (MAILHOST != null) {
props.put("", MAILHOST);

// Get a Session object
Session session = Session.getDefaultInstance(props, null);

try {

// Construct the email
Message msg = new MimeMessage(session);

// Set From
if (FROM != null) {
msg.setFrom(new InternetAddress(FROM));
} else {

// Set Subject

// Set Text

// Add Recipient
InternetAddress.parse(TO, false));

// Sent Date
msg.setSentDate(new Date());

// Send Email SMS

LASTERROR = "Success.";
return true;
} catch (MessagingException mex) {
LASTERROR = mex.getMessage();
return false;
[ September 15, 2008: Message edited by: Chandrasekhar Mangipudi ]
Dilwan Sujan Cuttilan
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You Friends,

Please understand the problem.

There is a GSM modem with a sim running in my machine. What i need is to send sms to this modem using a j2me application. I am able to send sms to this modem using my phone nokia 3110c via a j2me application. But it is not working with nokia 6300.

And when i press the send button in my j2me application in my mobile it is asking again to verify to send the message. Once i press yes the sms is sent. Why is it happening? And is there a way to get the delivery report?

Please help
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic