Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending email

Status
Not open for further replies.

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 ?



 
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(&quot;MAIL FROM:<remite@dominio.com>\r\n&quot;);
System.out.println(is.readLine());

os.writeBytes(&quot;RCPT TO:<destino@dominio.com>\r\n&quot;);
System.out.println(is.readLine());

os.writeBytes(&quot;DATA\r\n&quot;);
System.out.println(is.readLine());
//Poner aquí el mensaje
//Cada salto de linea, \r\n
os.writeBytes(&quot;Your message\r\n&quot;);

//Final mensaje
os.writeBytes(&quot;\r\n.\r\n&quot;);//Valor fijo
System.out.println(&quot;Fin del Mail.&quot;+is.readLine());
}
catch (Exception ex){System.out.println(&quot;Mensaje no enviado\n&quot;+ex);}
}
public static void main(String ar[])
{nombreIP INICIO=new nombreIP();}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top