Newsgroup: it.comp.programmare.win32
Titolo: Funzione per inviare e-mail

Ciao a tutti, volevo sapere se qualcuno sa darmi qualche indicazione
per scrivere una funzione in c++ che invii una e-mail con un file in
attachment.
grazie.

1- Devi guardarti per bene la programmazione dei socket (in coda una
piccola classe da me scritta tempo fa che forse puo' aiutarti nel
compito)
2- Una volta imparato a programmare i socket, devi impararti il
protocollo SMTP


class ClientSocket
{
private:
	SOCKET s;
	WSADATA wsadata;
	SOCKADDR_IN destination;
////////////////////////////////////////////////////////////////////////
////
	int FillAddress(PSOCKADDR_IN psin, char *HostName, unsigned
short portno)
	/*
	  Ottiene l'indirizzo per poter effettuare la connessione.
	  E' una funzione privata.
	*/
	{
		PHOSTENT phe;
		phe = gethostbyname(HostName);
		if(phe==NULL)
		{
			LastErrorCode=WSAGetLastError();
			return -1;
		}
		memcpy((char FAR *)&(psin->sin_addr), phe->h_addr,
phe->h_length);
		psin->sin_family=AF_INET;
		psin->sin_port=htons(portno);
		return 0;
	}
public:
	int LastErrorCode;
////////////////////////////////////////////////////////////////////////
////
	bool Initialize(void)
	/*
	  Inizializza la classe e quant'altro va inizializzato.
	*/
	{
		if(WSAStartup(0x202, &wsadata)!=0)
		{
			LastErrorCode=WSAGetLastError();
			return false;
		}
		s=socket(AF_INET, SOCK_STREAM, 0);
		if(s==INVALID_SOCKET)
		{
			LastErrorCode=WSAGetLastError();
			return false;
		}
		return true;
	}
////////////////////////////////////////////////////////////////////////
////
	void UnInitialize(void)
	{
		closesocket(s);
		WSACleanup();
	}
////////////////////////////////////////////////////////////////////////
////
	bool SetBlockingMode(void)
	{
		unsigned long IO_opt=0;
		if(ioctlsocket(s,FIONBIO,&IO_opt)==SOCKET_ERROR)
		{
			LastErrorCode=WSAGetLastError();
			return false;
		}
		return true;
 
	}
////////////////////////////////////////////////////////////////////////
////
	bool Connect(char *HostName, unsigned short Port)
	{
		unsigned long IO_opt=1;
		if(FillAddress(&destination, HostName, Port)==-1)
			return false;
		if(connect(s, (PSOCKADDR)&destination,
sizeof(destination))==SOCKET_ERROR)
		{
			LastErrorCode=WSAGetLastError();
			return false;
		}
		if(ioctlsocket(s,FIONBIO,&IO_opt)==SOCKET_ERROR)
		{
			LastErrorCode=WSAGetLastError();
		}
		return true;
	}
////////////////////////////////////////////////////////////////////////
////
	int Receive(char *Buffer, int BufSize)
	{
		int i;
		memset(Buffer, 0, BufSize);
		i=recv(s, Buffer, BufSize, 0);
		if(i==SOCKET_ERROR)
		{
			LastErrorCode=WSAGetLastError();
			return -1;
		}
		return i;
	}
////////////////////////////////////////////////////////////////////////
////
	int Send(char *Buffer, int BufSize)
	{
		int i;
		i=strlen(Buffer);
		i=send(s, Buffer, i, 0);
		if(i==SOCKET_ERROR)
		{
			LastErrorCode=WSAGetLastError();
			return -1;
		}
		return i;
	}
////////////////////////////////////////////////////////////////////////
////
	void LastErrorStr(char *ErrBuffer, int BufSize)
		/*
		  La funzione ritorna la descrizione dell'ultimo errore
incorso.
		*/
	{
		char ErrCodeStr[6];
		itoa(WSAGetLastError(), ErrCodeStr, 10);
		switch(LastErrorCode)
		{
			case WSASYSNOTREADY:
				memcpy(ErrBuffer, "underlying network
subsystem not ready.", BufSize);
				break;
			case WSAVERNOTSUPPORTED:
				memcpy(ErrBuffer, "The version of
Windows Sockets support requested is not provided.", BufSize);
				break;
			case WSAEINPROGRESS:
				memcpy(ErrBuffer, "A blocking Windows
Sockets 1.1 operation is in progress.", BufSize);
				break;
			case WSAEPROCLIM:
				memcpy(ErrBuffer, "Limit on the number
of tasks supported by the Windows Sockets implementation has been
reached.", BufSize);
				break;
			case WSAEFAULT:
				memcpy(ErrBuffer, "The lpWSAData is not
a valid pointer.", BufSize);
				break;
			case WSANOTINITIALISED:
				memcpy(ErrBuffer, "A successful
WSAStartup must occur before using this function.", BufSize);
				break;
			case WSAENETDOWN:
				memcpy(ErrBuffer, "The network subsystem
or the associated service provider has failed.", BufSize);
				break;
			case WSAEAFNOSUPPORT:
				memcpy(ErrBuffer, "The specified address
family is not supported.", BufSize);
				break;
			case WSAEMFILE:
				memcpy(ErrBuffer, "No more socket
descriptors are available.", BufSize);
				break;
			case WSAENOBUFS:
				memcpy(ErrBuffer, "No buffer space is
available. The socket cannot be created.", BufSize);
				break;
			case WSAEPROTONOSUPPORT:
				memcpy(ErrBuffer, "The specified
protocol is not supported.", BufSize);
				break;
			case WSAEPROTOTYPE:
				memcpy(ErrBuffer, "The specified
protocol is the wrong type for this socket.", BufSize);
				break;
			case WSAESOCKTNOSUPPORT:
				memcpy(ErrBuffer, "The specified socket
type is not supported in this address family.", BufSize);
				break;
			case WSAEADDRINUSE:
				memcpy(ErrBuffer, "A process on the
machine is already bound to the same fully-qualified address and the
socket has not been marked to allow address re-use with SO_REUSEADDR.",
BufSize);
				break;
			case WSAEADDRNOTAVAIL:
				memcpy(ErrBuffer, "The specified address
is not a valid address for this machine.", BufSize);
				break;
			case WSAEINVAL:
				memcpy(ErrBuffer, "The socket is already
bound to an address or socket not bound.", BufSize);
				break;
			case WSAENOTSOCK:
				memcpy(ErrBuffer, "The descriptor is not
a socket.", BufSize);
				break;
			case WSAEISCONN:
				memcpy(ErrBuffer, "The socket is already
connected.", BufSize);
				break;
			case WSAEOPNOTSUPP:
				memcpy(ErrBuffer, "The referenced socket
is not of a type that supports the listen operation.", BufSize);
				break;
			case WSAEINTR:
				memcpy(ErrBuffer, "A blocking Windows
Socket 1.1 call was canceled through WSACancelBlockingCall.", BufSize);
				break;
			case WSAEWOULDBLOCK:
				memcpy(ErrBuffer, "The socket is marked
as nonblocking and no connections are present to be accepted.",
BufSize);
				break;
			case 0:
				memcpy(ErrBuffer, "No errors", BufSize);
				break;
			default:
				memcpy(ErrBuffer, ErrCodeStr, BufSize);
				break;
		}
	}
};

 protocollo SMTP
ti ringrazio ma ho ancora un problema...quando provo a compilare il
codice che mi hai inviato ottengo un errore nel linkaggio di questo
tipo:
-------------------------------------------------------------------------------
Linking...
socket2.obj : error LNK2001: unresolved external symbol
__imp__socket@12
socket2.obj : error LNK2001: unresolved external symbol
__imp__WSAGetLastError@0
socket2.obj : error LNK2001: unresolved external symbol
__imp__WSAStartup@8
Debug/socket2.exe : fatal error LNK1120: 3 unresolved externals
-------------------------------------------------------------------------------
qualcuno sa spiegarmi il perchč?
ciao