Home > Articles > Programming > Java

  • Print
  • + Share This
From the author of


If you want to avoid the trouble of setting up your computer as an SMS gateway, you could send SMS messages using email. Many cell phone service providers let you send an SMS message to a cell phone via email, the text of which contains the SMS message to an email address with the following address format:


For example, suppose I want to send an SMS message to a friend's cell phone. (For that matter, I could send it to his land line if the land line caller ID hardware is configured to display SMS, and my friend's telecom company supports the reception of email-to-SMS messages.) I write the following code that uses JavaMail:

public class SMSbyEMail {
  String msg;
  public SMSbyEMail(SMSNum) {
   //Set the message
   smsMsg = "Come to my party dude!" ;
   //Do some Java Mail configuration stuff
   boolean sessionDebug = false;
   Properties props = System.getProperties();
   props.put("mail.host", "");
   props.put("mail.transport.protocol", "smtp");
   Session mailSession = Session.getDefaultInstance(props, null);
   try {
     //Configure the SMTP message
     Message msg = new MimeMessage(mailSession);
     msg.setFrom(new InternetAddress("party@dudes.com"));
     InternetAddress[] address = {new
     InternetAddress(SMSNum + "@hisCellCompany.net")};
     msg.setRecipients(Message.RecipientType.TO, address);
     msg.setSentDate(new Date());
   catch (Exception e) {
     System.out.println("No go: " + e);
  • + Share This
  • 🔖 Save To Your Account