Nov 19, 2001 #1 yaronb Programmer Jan 6, 2001 13 IL Hi... I want to send email from my program - a very simple one... Can any body help me ?
Nov 19, 2001 #2 varocho Programmer Dec 4, 2000 238 US You can use the JavaMail API, available at: http://java.sun.com/products/javamail/index.html Upvote 0 Downvote
Nov 25, 2001 #3 jdjuanci Programmer Jun 30, 2001 4 ES JuanCi I recommend search smtp protocol info You must end each line with \r\n You must end you message with a dot \r\n.\r\n import java.net.*;import java.io.*; public class nombreIP{ //Streams de comunicación DataInputStream is; DataOutputStream os; public nombreIP(){ System.out.println("declaro sk" try{//Abrir socket Socket sk=new Socket("smtp.server.com", 25); os=new DataOutputStream(sk.getOutputStream()); is=new DataInputStream(sk.getInputStream()); //Respuesta del servidor System.out.println(is.readLine()); //Me identifico String local; local=InetAddress.getLocalHost().toString(); os.writeBytes("HELO "+local+"\r\n" System.out.println(is.readLine()); //Datos mensaje os.writeBytes("MAIL FROM:<remite@dominio.com>\r\n" System.out.println(is.readLine()); os.writeBytes("RCPT TO:<destino@dominio.com>\r\n" System.out.println(is.readLine()); os.writeBytes("DATA\r\n" System.out.println(is.readLine()); //Poner aquí el mensaje //Cada salto de linea, \r\n os.writeBytes("Your message\r\n" //Final mensaje os.writeBytes("\r\n.\r\n"//Valor fijo System.out.println("Fin del Mail."+is.readLine()); } catch (Exception ex){System.out.println("Mensaje no enviado\n"+ex);} } public static void main(String ar[]) {nombreIP INICIO=new nombreIP();} } Upvote 0 Downvote
JuanCi I recommend search smtp protocol info You must end each line with \r\n You must end you message with a dot \r\n.\r\n import java.net.*;import java.io.*; public class nombreIP{ //Streams de comunicación DataInputStream is; DataOutputStream os; public nombreIP(){ System.out.println("declaro sk" try{//Abrir socket Socket sk=new Socket("smtp.server.com", 25); os=new DataOutputStream(sk.getOutputStream()); is=new DataInputStream(sk.getInputStream()); //Respuesta del servidor System.out.println(is.readLine()); //Me identifico String local; local=InetAddress.getLocalHost().toString(); os.writeBytes("HELO "+local+"\r\n" System.out.println(is.readLine()); //Datos mensaje os.writeBytes("MAIL FROM:<remite@dominio.com>\r\n" System.out.println(is.readLine()); os.writeBytes("RCPT TO:<destino@dominio.com>\r\n" System.out.println(is.readLine()); os.writeBytes("DATA\r\n" System.out.println(is.readLine()); //Poner aquí el mensaje //Cada salto de linea, \r\n os.writeBytes("Your message\r\n" //Final mensaje os.writeBytes("\r\n.\r\n"//Valor fijo System.out.println("Fin del Mail."+is.readLine()); } catch (Exception ex){System.out.println("Mensaje no enviado\n"+ex);} } public static void main(String ar[]) {nombreIP INICIO=new nombreIP();} }