java left logo
java middle logo
java right logo
 

Home arrow Java ME Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4094
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Sending e-mail from a mobile device E-mail
User Rating: / 9
PoorBest 

This tip demonstrates a method of sending a mail from a handset. Wireless portals support many of the same applications as Internet portals. For example they provide messaging services, which includes electronic mail. So this tip in J2ME may be very helpful for developers who want to implement these type of services.

void sendMail() 
{
  SocketConnection sc=null;
  InputStream is=null;
  OutputStream os=null;

  //Login to mail server
  try {

    byte b[]=new byte[200];
    int total=0;
    sc = (SocketConnection)
    Connector.open("socket://"+servAdd+":110");
    is = sc.openInputStream();
    os = sc.openOutputStream();
    os.write(("USER  This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ").getBytes())
    total=is.read(b);
    response+=new String(b,0,total);
    os.write(("PASS 123\r\n").getBytes());
    total=is.read(b);
    response+=new String(b,0,total);
      
    // Sending mail
           sc = (SocketConnection)Connector.open("socket://"+serverAdd+":25");
           is = sc.openInputStream();
           os = sc.openOutputStream();
    os.write(("HELO there" "\r\n").getBytes())
    os.write(("MAIL FROM:  This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ").getBytes());
    os.write(("RCPT TO:  This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ").getBytes());
    os.write("DATA\r\n".getBytes());
    os.write(("From:  This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ").getBytes());
    os.write(("To:  This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ").getBytes());
    os.write(("Subject: "+subject+"\r\n").getBytes());
    os.write((msg+"\r\n").getBytes())// message body
    os.write(".\r\n".getBytes());
    os.write("QUIT\r\n".getBytes());    

  catch(Exception e){}

  


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.