Visualizzazione dei risultati da 1 a 10 su 10

Discussione: [C] Spedire mail

  1. #1

    [C] Spedire mail

    Ciao, mi chiedevo come fare per spedire una mail !!!
    La mail la posso anche magari salvare come .eml e metterla dentro l'exe, ma come faccio a spedirla a dei destinatari (diciamo statici e preimpostati, un passettino alla volta!)

    dai dai dai aiutatemi

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2004
    Messaggi
    50
    Devi utilizzare il protocollo SMTP. Non sarebbe difficile se non ci si dovesse autenticare ad un server pubblico di posta. Io non ci sono riuscito...
    Ho ripiegato su VB(mooolto piu' facile...) Cmq qualche informazione la trovi in questa discussione. http://forum.html.it/forum/showthrea...78#post5376278

    ciao.

  3. #3
    caspio

    hai mica in giro il codice che hai postato sull'altro 3d ? li è incompleto e sai io nn sono una cima...anche senza autenticazione, tanto per studiarmelo...

    mi saresti di grande aiuto si sa mai che capisco come caspio
    autenticarmi..

  4. #4
    Utente di HTML.it
    Registrato dal
    Feb 2004
    Messaggi
    50
    Ecco qua.
    Buon lavoro.
    codice:
    #include <stdio.h>
    #include <winsock.h>
    #include <stdlib.h>
    
    //#define PORT 6644
    #define PORT 25
    
    #define MESHELO "EHLO ciao\r\n\0"    
    #define MESQUIT "QUIT\r\n\0"    
    #define MESMFROM "MAIL FROM: <pippo@tin.it>\r\n\0"    
    #define MESRCPT "RCPT TO:<pluto@tiscali.it>\r\n\0"    
    #define MESDATA "DATA\r\n\0"    
    #define MESSAGEP "prova email\r\n\0"    
    #define MESPUNTO ".\r\n\0"    
    #define MESHELP "HELPP DATA\r\n\0"    
    #define MESNOOP "NOOP\r\n\0"    
    #define MESAUTH "AUTH PLAIN\r\n\0"    
    #define MESAUTHL "AUTH=\r\n\0"    
    
    #define MAX_STRING 5120
    
    void client(char *);
    void error(char *);
    int InitializeWinsock(WORD );
    void Usage();
    
    int main(int argc, char *argv[])
    {
    	if ( argc < 2 ) Usage();
    
    	if (strcmp(argv[1], "client") == 0 )
    	{
    		// initialize wsock32.dll, requesting winsock 1.1
    		if (argc!=3 ) Usage();
    		if (!InitializeWinsock (MAKEWORD(1,1) ) ) return 1;
    		client(argv[2]);
    		WSACleanup();
    	}
    	return 0;
    }
    
    void client(char * server_IP)
    {
    SOCKET fd; 			// "file" descriptor for the network socket
    SOCKADDR_IN saddr;
    char buf[MAX_STRING];
    
        struct hostent *h;
    
        if ((h=gethostbyname(server_IP)) == NULL) {  /* get the host info */
    		error("gethostbyname");
            exit(1);
        }
        printf("Host name  : %s\n", h->h_name);
        printf("IP Address : %s\n\n",inet_ntoa(*((struct in_addr *)h->h_addr)));
    
    	if ((fd=socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET)
    		error("Client: socket not connected ");
    
    	saddr.sin_family = AF_INET;
    	saddr.sin_addr.s_addr = inet_addr(inet_ntoa(*((struct in_addr *)h->h_addr))); 
    	saddr.sin_port = htons(PORT);
    	
    	// request connection to server socket (remote machine)
    	if (connect(fd, (LPSOCKADDR) &saddr, sizeof(saddr)) == SOCKET_ERROR)
    		error("Client: connect ");
    
    	if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
    		error("Client: receiving failure ");
    
    	printf("Server echoed1 '%s' \n",buf);
    	
    	if( send(fd, MESHELO, strlen(MESHELO)+1, 0) == SOCKET_ERROR )
    		error("Server: sending failure ");
     		
    	if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
    		error("Client: receiving failure ");
    
    	printf("Server echoed2 '%s' \n",buf);
    //----
    	//if( send(fd, MESHELP, strlen(MESHELP)+1, 0) == SOCKET_ERROR )
    	//	error("Server: sending failure ");
    
     	send(fd, MESAUTH, strlen(MESAUTH)+1, 0);
    	
    	if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
    		error("Client: receiving failure ");
    
    	printf("Server echoed3 '%s' \n",buf);
    
    	if( send(fd, MESQUIT, strlen(MESQUIT)+1, 0) == SOCKET_ERROR )
    		error("Server: sending failure ");
     		
    	if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
    		error("Client: receiving failure ");
    
    	printf("Server echoed4 '%s' \n",buf);
    //<<<<<
    //---	
    /*	
    	//if( send(fd, MESMFROM, strlen(MESMFROM)+1, 0) == SOCKET_ERROR )
    	//	error("Server: sending failure ");
     		
    	//if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
    	//	error("Client: receiving failure ");
    
    	//printf("Server echoed3 '%s' \n",buf);
    	//if( send(fd, MESRCPT, strlen(MESRCPT)+1, 0) == SOCKET_ERROR )
    	//	error("Server: sending failure ");
     		
    	//if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
    	//	error("Client: receiving failure ");
    
    	//printf("Server echoed4 '%s' \n",buf);
    	//if( send(fd, MESDATA, strlen(MESDATA)+1, 0) == SOCKET_ERROR )
    	//	error("Server: sending failure ");
     		
    	//if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
    	//	error("Client: receiving failure ");
    
    	printf("Server echoed5 '%s' \n",buf);
    	//if( send(fd, MESSAGEP, strlen(MESSAGEP)+1, 0) == SOCKET_ERROR )
    	//	error("Server: sending failure ");
     		
    	if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
    		error("Client: receiving failure ");
    
    	printf("Server echoed6 '%s' \n",buf);
    	//if( send(fd, MESPUNTO, strlen(MESPUNTO)+1, 0) == SOCKET_ERROR )
    	//	error("Server: sending failure ");
     		
    	if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
    		error("Client: receiving failure ");
    
    	printf("Server echoed7 '%s' \n",buf);
    	//if( send(fd, MESQUIT, strlen(MESQUIT)+1, 0) == SOCKET_ERROR )
    	//	error("Server: sending failure ");
     		
    	if( recv(fd, buf, sizeof(buf), 0) == SOCKET_ERROR )
    		error("Client: receiving failure ");
    
    	printf("Server echoed8 '%s' \n",buf);
    	*/
    
    	printf("Sending 'Connection Closing' command\n\n");
    
    	if (closesocket(fd) == SOCKET_ERROR)
    		error("Client: closing socket ");
    }
    
    /**********************************************
    * Windows Sockets Initialization              *
    **********************************************/
    
    int InitializeWinsock(WORD wVersionRequested)
    {
    WSADATA wsaData;
    int err;
    
    	err = WSAStartup(wVersionRequested, &wsaData);
    
    	// ritorna errore se, ad esempio, l'applicazione supporta al massimo
    	// la versione 1.1 e la DLL supporta da 2.0 in su (le versioni non si sovrappongono)
    	if (err!=0) return 0; // Tell the user that we couldn't find a usable winsock.dll 
    
    	// WSAStartup returns in wHighVersion (struct wsaData) the highest version it supports
    	//  and in wVersion the minimum of its high version and wVersionRequested.
    	//  wVersion is the The version of the Windows Sockets specification 
    	//  that the Windows Sockets DLL expects the caller to use.
    
    	// Se WSAStartup ritorna un risultato accettabile, l'applicazione deve ancora 
    	//  verificare che il risultato sia compatibile con la sua richiesta. Ad esempio,
    	//  con wVersionRequested=1.1 e DLL version 1.0, wVersion=1.0. Se l'applicazione 
    	//  vuole assolutamente usare la DLL 1.1, deve ancora verificare di non trovarsi 
    	//  in questo caso
    
    	// Tell the user that we couldn't find a usable winsock.dll.
    	if (LOBYTE(wsaData.wVersion )!=1 || HIBYTE(wsaData.wVersion)!=1) return 0;
    
    	//Everything is fine: proceed
    	return 1;
    }
    
    
    /**********************************************
    * Error Handling Functions                    *
    **********************************************/
    
    void Usage()
    {
    	printf("\n\t Usage: tcp_sock server | client ip_server_address\n\n");
    	exit(1);
    }
    
    // define to save space
    #define PERR(X) fprintf(stderr, X); break
    
    void error(char* string) {
    int err;
        
    	fprintf(stderr, "%s", string);
    
    	err= WSAGetLastError();
        
    	//in Windows, gli errori dovuti ai sockets sono mappati oltre 10000
       	switch (err)
    	{
    	case WSANOTINITIALISED: 
                 PERR("A successful WSAStartup() must occur before using this API.");
    	case WSAENETDOWN:
                 PERR("The Windows Sockets implementation has detected that the network subsystem has failed.");
    	case WSAEAFNOSUPPORT:
                 PERR("The specified address family is not supported.");
    	case WSAEINPROGRESS:
                 PERR("A blocking Windows Sockets operation is in progress.");
    	case WSAEMFILE:
                 PERR("No more file descriptors are available.");
    	case WSAENOBUFS:
                 PERR("No buffer space is available. The socket cannot be created.");
    	case WSAEPROTONOSUPPORT:
                 PERR("The specified protocol is not supported.");
    	case WSAEPROTOTYPE:
                 PERR("The specified protocol is the wrong type for this socket.");
    	case WSAESOCKTNOSUPPORT:
                 PERR("The specified socket type is not supported in this address family.");
       	case WSAEADDRINUSE:
                 PERR("The specified address is already in use. (See setsockopt() SO_REUSEADDR option)");
        	case WSAEFAULT:
                 PERR("The namelen argument is too small (less than the size of a struct sockaddr).");
        	case WSAEINTR:
                 PERR("The (blocking) call was canceled via WSACancelBlockingCall()");
    	case WSAEINVAL:
                 PERR("The socket is already bound to an address.");
       	case WSAENOTSOCK:
                 PERR("The descriptor is not a socket.");
        	case WSAEADDRNOTAVAIL:
                 PERR("Address not availabile");
    	case WSAEISCONN:
                 PERR("The socket is already connected.");
    	case WSAEOPNOTSUPP:
                 PERR("The referenced socket is not of a type that supports the listen() operation.");
    	case WSAEWOULDBLOCK:
                 PERR("The socket is marked as non-blocking and no connections are present to be accepted.");
    	case WSAECONNREFUSED:
                 PERR("The attempt to connect was forcefully rejected.");
    	case WSAEDESTADDRREQ:
                 PERR("A destination address is required.");
    	case WSAENETUNREACH:
                 PERR("The network can't be reached from this host at this time.");
    	case WSAETIMEDOUT:
                 PERR("Attempt to connect timed out without establishing a connection");
           	case WSAECONNRESET:
                 PERR("Connection reset");
           
    	default:
                 fprintf(stderr, "Error reported by WSAGetLastError= %d\n Check winsock.h.\n\n", err); break;
    	};
    
    	exit(1);
    	}

  5. #5
    Utente di HTML.it
    Registrato dal
    Feb 2004
    Messaggi
    50
    tanto per farti un'idea sul protocollo SMTP puoi guardare qui : http://www.feelinglinux.com/articoli/smtp.ggj

  6. #6
    grazie mille, domani testo

    quali librerie devo linkare ?

  7. #7
    Utente di HTML.it
    Registrato dal
    Feb 2004
    Messaggi
    50
    questa : wsock32

  8. #8
    perfetto !

    come tcp_sock server | client ip_server_address

    cosa mi consigli per delle prove online ?

  9. #9
    Utente di HTML.it
    Registrato dal
    Feb 2004
    Messaggi
    50
    puoi andare sulle proprieta' del tuo account del programma di posta e usi il server associato al parametro SMTP. Purtroppo ora non ho sottomano quelli con cui ho provato io.

  10. #10
    Utente di HTML.it
    Registrato dal
    Feb 2004
    Messaggi
    50
    io provavo eseguendo il pgm cosi :
    miopgm client mail.clubnet.tin.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.