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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

hOW CAN I SEND AN SMS

 
Greenhorn
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.
 
author
Posts: 3281
8
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.io.*;
import java.net.InetAddress;
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 SUBJECT;
String TEXT;
String MAILHOST;
String LASTERROR;

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

SMS.setMailHost("mail.domain.com");
SMS.setTo("1234567890@messaging.nextel.com");
SMS.setFrom("name@domain.com");
SMS.setSubject("");
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() {
return LASTERROR;
}

// 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("mobile.att.net") > 0) {
maxLength = 140;
} else if (TO.indexOf("messaging.nextel.com") > 0) {
maxLength = 280;
} else if (TO.indexOf("messaging.sprintpcs.com") > 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("mail.smtp.host", 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 {
msg.setFrom();
}

// Set Subject
msg.setSubject(SUBJECT);

// Set Text
msg.setText(TEXT);

// Add Recipient
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(TO, false));

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

// Send Email SMS
Transport.send(msg);

LASTERROR = "Success.";
return true;
} catch (MessagingException mex) {
LASTERROR = mex.getMessage();
return false;
}
}
}
[ September 15, 2008: Message edited by: Chandrasekhar Mangipudi ]
 
Dilwan Sujan Cuttilan
Greenhorn
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
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic