Caros amigos da lista, estou encontrando dificuldades para enivar e-mail
via Java.
Comecei a fazer uma classe, mas eu consigo me conectar com o servidor, vejo
vers�o tudo mais do servidor, s� que n�o consigo enviar
a mensagem.
Estou enviando o codigo. Caso  alguem possa me ajudar ficaria muito
agradecido.

Obrigado.
Anderson A. De Bona.
[EMAIL PROTECTED]

package Orautil;

import java.io.*;
import java.net.*;
import java.util.*;

public class Enviar_mail extends Object {
    public String host;
    public int port;

    public String recipient;
    public String sender;
    public String[] message;

    protected Socket sessionSock;
    protected DataInputStream inStream;
    protected DataOutputStream outStream;

    public Enviar_mail(){
    }

    public Enviar_mail(String host, String recipient, String sender,
        String[] message) throws IOException {
        this.host = "smtp.uol.com.br";
        this.port = 25;
        this.recipient = recipient;
        this.message = message;
        this.sender = sender;
    }
    public Enviar_mail(String host, int port, String recipient, String
sender,
         String[] message) throws IOException {
         this.host = host;
         this.port = port;
         if (this.port <=0) this.port = 25;
         this.recipient = recipient;
         this.message = message;
         this.sender = sender;
    }
    //Encerra a sessao

    public void close() throws IOException {
         sessionSock.close();
         sessionSock = null;
    }
    //Conecta com o servidor

    protected void connect() throws IOException {
        sessionSock = new Socket(host, port);
        inStream = new DataInputStream(sessionSock.getInputStream());
        outStream = new DataOutputStream(sessionSock.getOutputStream());
    }
    //Envia um comando e espera por uma resposta

    protected String doCommand(String commandString) throws IOException {
        outStream.writeBytes(commandString+"\n");
        String response = getResponse();
        return response;
    }

    protected String getResponse() throws IOException {
        String response = " ";
        for (;;) {
            String line = inStream.readLine();
            if (line == null) {
               throw new IOException("O servidor nao responde");
            }

            if (line.length() <3) {
               throw new IOException("O servidor nao responde.");
            }
            response += line + "\n";


            if ((line.length() == 3) || (line.charAt(3) != '-'))
               return response;
       }
   }
   // Envia uma resposta usando o protocolo SMTP

    public void sendMessage() throws IOException {
        connect();

         String response = getResponse();
         if (response.charAt(0) != '2') {
             throw new IOException(response);
         }
         response = doCommand("helo host.com");

         if (response.charAt(0) != '2') {
              throw new IOException(response);
         }

         response = doCommand("MAIL FROM:" + sender);

         if (response.charAt(0) != '2') {
               throw new IOException(response);
         }

         response = doCommand("RCPT TO:"  + recipient);

         if (response.charAt(0) != '2') {
               throw new IOException(response);
         }

         response = doCommand("DATA");

         if (response.charAt(0) != '3') {
               throw new IOException(response);
         }

        for (int i=0; i < message.length; i++) {

        if (message[i].length() == 0) {
            outStream.writeBytes("\n");
            continue;
        }
        if (message[i].charAt(0) == '.') {
            outStream.writeBytes("." + message[i] + "\n");
        } else {
            outStream.writeBytes(message[i] + "\n");
        }
    }

        response = doCommand(".");
        if (response.charAt(0) != '2') {
            throw new IOException(response);
        }

        close();
     }
 }





* Para n�o receber mais e-mails desta lista envie um e-mail para 
[[EMAIL PROTECTED]]
e no corpo do email escreva [unsubscribe <seu-email>] ou acesse 
http://apoio.cits.br:8080/guest/RemoteListSummary/javabr
Veja as mensagens antigas em http://www.mail-archive.com/javabr%40cits.br/

Responder a