<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<STYLE>.hmmessage P {
PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px
}
BODY.hmmessage {
FONT-SIZE: 10pt; FONT-FAMILY: Tahoma
}
</STYLE>
<META content="MSHTML 6.00.6000.16674" name=GENERATOR></HEAD>
<BODY class=hmmessage bgColor=#ffffff>
<DIV><FONT face=Arial>Saludos,</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>Les comento, estoy intentando hacer algo para el envio de
correos electrónicos, he leído mucho acerca de los sockets y protocolo smtp, he
logrado hacer que abra el socket, que se conecte al servidor smtp. Hasta ahí
todo bien, pero, ahora quiero empezar la "charla" con el servidor SMTP, ahi es
donde ya no se como hacerle, he estado usando la funcion recv() en primer paso,
pero no responde el server. Tengo por seguro que algo me falta, pero no logro
saber que.</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>Agradeceré mucho me ayuden a disipar la duda y me digan
que me falta y porque.</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>este es el código en cuestión.</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>#include <windows.h><BR>#include
<winsock2.h><BR>#include <stdio.h><BR>#include
<stdlib.h><BR>#include <errno.h><BR>#include
<string.h><BR>#include <unistd.h></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial>#define DEFAULT_BUFLEN 100</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial>int ioctlsocket(SOCKET s, long cmd, u_long FAR
*argp);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial>void sendsmtp( char *ServidorSMTP, int DEST_PORT
)<BR>{<BR> WSADATA wsaData;<BR> int iresult;<BR> int
sockfd;<BR> int recvbuflen = DEFAULT_BUFLEN;<BR> struct
sockaddr_in dest_addr; // Guardará la dirección de destino<BR> struct
hostent *hServSMTP;<BR> char *sendbuf = "this is a
test";<BR> char recvbuf
[DEFAULT_BUFLEN];<BR> char buffer [33];<BR>
u_long iMode = 0;<BR> int numbytes = 0;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT
face=Arial> /////////////////////////////////////////////////////<BR> ////
Inicio de la Conexión
////<BR> /////////////////////////////////////////////////////<BR> if
(WSAStartup(MAKEWORD(2, 2), &wsaData) !=
NO_ERROR)<BR> {<BR> MessageBox( NULL, "No se pudo crear
el enlace WINSOCK", "INCOS", MB_OK );<BR>
WSACleanup();<BR> exit(1);<BR> }<BR> <BR> if
((hServSMTP=gethostbyname(ServidorSMTP)) ==
NULL)<BR> {<BR> // Obtener información
del host<BR> MessageBox( NULL, "El dns no existe,
verifique...", "INCOS", MB_OK );<BR>
WSACleanup();<BR> exit(1);<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial> sockfd = socket(AF_INET, SOCK_STREAM,
0);<BR> if (sockfd ==
INVALID_SOCKET)<BR> {<BR> MessageBox(
NULL, "No hubo socket", "INCOS", MB_OK
);<BR> WSACleanup();<BR>
exit(1);<BR> }<BR> <BR> dest_addr.sin_family = AF_INET; //
Ordenación de máquina<BR> dest_addr.sin_port = htons(DEST_PORT); // short,
Ordenación de la red<BR> dest_addr.sin_addr = *((struct in_addr
*)hServSMTP->h_addr);<BR> memset(&(dest_addr.sin_zero), '\0', 8); //
Poner a cero el resto de la estructura<BR> <BR> // Coloca el socket no
bloqueado<BR>
//-------------------------<BR> // Set the socket I/O mode: In
this case FIONBIO<BR> // enables or disables the blocking mode
for the <BR> // socket based on the numerical value of
iMode.<BR> // If iMode = 0, blocking is enabled;
<BR> // If iMode != 0, non-blocking mode is
enabled.<BR> iresult = ioctlsocket(sockfd, FIONBIO,
&iMode); <BR> if ( iresult ==
SOCKET_ERROR )<BR> {<BR>
MessageBox( NULL, "No se puede desbloquear el socket...", "INCOS", MB_OK
);<BR> WSACleanup();<BR>
exit(1);<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial> iresult = connect(sockfd, (struct sockaddr *)
&dest_addr, sizeof(struct sockaddr));<BR> if ( iresult == SOCKET_ERROR
)<BR> {<BR> MessageBox( NULL, "No hubo
conexión al socket", "INCOS", MB_OK );<BR>
WSACleanup();<BR> exit(1);<BR>
}<BR> <BR> // Send an initial
buffer<BR> iresult = send( sockfd, sendbuf,
(int)strlen(sendbuf), 0 );<BR> if (iresult ==
SOCKET_ERROR)<BR> {<BR>
MessageBox( NULL, "Falló el enviar (send)", "INCOS", MB_OK
);<BR>
closesocket(sockfd);<BR>
WSACleanup();<BR> exit(1);<BR>
}<BR> <BR> MessageBox( NULL, ServidorSMTP,
"Conectado a...", MB_OK );<BR> <BR> if (
(numbytes = recv(sockfd, recvbuf, DEFAULT_BUFLEN, 0)) == SOCKET_ERROR
) <BR>
{<BR> itoa(
WSAGetLastError(),buffer,10
);<BR> MessageBox( NULL, buffer,
"recv ha fallado, error...", MB_OK );<BR>
}<BR> else<BR>
{<BR>
recvbuf[numbytes]='\0';<BR>
MessageBox( NULL, recvbuf, "Lo recibido...", MB_OK );<BR>
}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT
face=Arial> /////////////////////////////////////////////////////<BR> ////
Fin de la Conexion
////<BR> /////////////////////////////////////////////////////<BR> shutdown(sockfd,2);<BR> closesocket(sockfd);<BR> WSACleanup();<BR>}<BR></FONT></DIV>
<DIV><FONT face=Arial>Les comento que uso Dev-C++</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>saludos y gracias de antemano</FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT face=Arial>William Morales</DIV></FONT></BODY></HTML>