como mandar mail en java

luis antonio
31 de Agosto del 2003
hola, como puedo mandar mail desde java sin tener cuentas pop

nakune
31 de Agosto del 2003
primero necesitas instalar un servidor SMTP en tu máquina, y luego con una clase parecida a esta deberías poder:

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

public class Correo2 {

public static void main(String []args) {
new Correo2();

}

Correo2(){

try {
Socket s = new Socket("localhost", 25);
BufferedReader in = new BufferedReader
(new InputStreamReader(s.getInputStream(), "8859_1"));
BufferedWriter out = new BufferedWriter
(new OutputStreamWriter(s.getOutputStream(), "8859_1"));
for (int i =0;i<1;i++){
send(in, out, "HELO theWorld");
// warning : some mail server validate the sender address
// in the MAIL FROm command, put your real address here
send(in, out, "MAIL FROM: [email protected]");
send(in, out, "RCPT TO: [email protected]" );
send(in, out, "DATA");
send(out, "Subject: In the ghetto");
send(out, "From: Asunto<[email protected]>");
send (out, "n");
// message body
send(out, "I'm alive. Help me!");
send(out, "n.n");
}
send(in, out, "QUIT");

s.close();
}
catch (Exception e) {
e.printStackTrace();
}
}

public void send(BufferedReader in, BufferedWriter out, String s) {
try {
out.write(s + "n");
out.flush();
System.out.println(s);
s = in.readLine();
System.out.println(s);
}
catch (Exception e) {
e.printStackTrace();
}
}

public void send(BufferedWriter out, String s) {
try {
out.write(s + "n");
out.flush();
System.out.println(s);
}
catch (Exception e) {
e.printStackTrace();
}
}
}