EMSI MIAGE
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Le Deal du moment : -39%
Ordinateur portable ASUS Chromebook Vibe CX34 Flip
Voir le deal
399 €

Messagerie la partie d'envoie d'un email

2 participants

Aller en bas

Messagerie  la partie d'envoie d'un email Empty Messagerie la partie d'envoie d'un email

Message  DAFALI Ven 16 Jan - 2:03

Bonjour

je vous présente la partie qui permet de se connecter et d'envoyer un email à partir du mobile vers un serveur messagerie


Code:


import java.io.InputStream;
import java.io.OutputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.SocketConnection;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class Messagerie extends MIDlet implements CommandListener{
   
   private Command exitCommand = new Command("Exit", Command.EXIT, 1);
   private Command valider = new Command("valider", Command.SCREEN, 2);
   TextField to=new TextField("TO", "", 25, TextField.EMAILADDR);
    TextField data=new TextField("Message", "", 30, TextField.ANY);
    Form f=new Form("Send Mail");
   
    Display d=Display.getDisplay(this);
   
   public Messagerie() {
      // TODO Auto-generated constructor stub
   }

   protected void destroyApp(boolean arg0)  {
      // TODO Auto-generated method stub

   }

   protected void pauseApp() {
      // TODO Auto-generated method stub

   }

   protected void startApp() throws MIDletStateChangeException {
      // TODO Auto-generated method stub
      f.append(to);
        f.append(data);
        f.addCommand(exitCommand);
        f.addCommand(valider);
        f.setCommandListener(this);
   
   
      d.setCurrent(f);
   }

   public void commandAction(Command c, Displayable d) {
      // TODO Auto-generated method stub
      if (c == exitCommand) {
            destroyApp(false);
            notifyDestroyed();
        }

      if (c == valider) {
        
         new Thread(new Runnable(){
            public void run(){
               try{
              
                  SocketConnection client=(SocketConnection)Connector.open("socket://localhost:25");
                 
                 
                 
                 
                 OutputStream os=client.openOutputStream();
                 InputStream is=client.openInputStream();
                 StringBuffer s=new StringBuffer();
                 
                  int c=0;
                 //envoie to
                 os.write("helo localhost\r\n".getBytes());
                    
                   
                 
                 //reception to
                                     
                                 
                  while((c=is.read())!=10&&c!=-1)
                  {
                  s.append((char)c);
                     
                  }
                 
                System.out.println(s.toString());
               
/////////////////////////////////
                //envoie mailfrom
               
                os.write("MAIL FROM:<expideteur@domaine.com>\r\n".getBytes());
                //reception mailfrom
                s=new StringBuffer("");
               
                while((c=is.read())!=10&&c!=-1)
                {
                s.append((char)c);
                   
                }
               
              System.out.println(s.toString());
         /////////////////////////////////////////////    
              //envoie rcpt
               
                os.write(("RCPT TO:<"+to.getString()+">\r\n").getBytes());
                //reception rcpt
                s=new StringBuffer("");
               
                while((c=is.read())!=10&&c!=-1)
                {
                s.append((char)c);
                   
                }
               
              System.out.println(s.toString());
             
/////////////////////////////////////////////    
              //envoie data
               
                os.write("DATA\r\n".getBytes());
                os.write(data.getString().getBytes());
                 os.write("\r\n.\r\n".getBytes());
                //reception data
                s=new StringBuffer("");
               
                while((c=is.read())!=10&&c!=-1)
                {
                s.append((char)c);
                   
                }
               
              System.out.println(s.toString());
             
/////////////////////////////////////////////    
              //envoie quit
               
                os.write("quit\r\n".getBytes());
               
             
             
                  os.close();    
                  is.close();
                  client.close();
                  
                  System.out.println(s);
                  
               }
               catch(Exception e){}
              
                
            }
         }).start(); 
      
   }

 
 }
}


DAFALI
Admin

Messages : 14
Date d'inscription : 16/01/2009

Revenir en haut Aller en bas

Messagerie  la partie d'envoie d'un email Empty Merci

Message  nesrine Ven 16 Jan - 2:10

Merci

nesrine

Messages : 3
Date d'inscription : 16/01/2009
Age : 38

Revenir en haut Aller en bas

Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum