Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

baskuenen

How do I implement my own - Client SMTP eMail Connection...

This topic is 6512 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here I go again with some stupid questions... My network knowledge is low, so please take it easy on me this time
Telnet and Hotmail:
  • Can I telnet to hotmail?
  • Can I simply use port 25?
  • Must I use http://www.hotmail.com or is myname@hotmail.com better?
  • Why doesn''t it still work?
  • SMTP client connection:
  • I already got the gethostbyname() and connect()
  • How do I send the subject and date?
  • Do I need to recv after a connect?
  • Do I need to recv() after each line send()?
  • I only want to send a single HTML page.
  • Is "Content-Type: text/html\r\n" all you need in the header?
  • Do I need an extra "\n" after the header before sending the HTML page?
  • It''s a lot of questions, so thanks already for reading them - Bas

    Share this post


    Link to post
    Share on other sites
    Advertisement
    Thanks Dak!

    After doing some more research, I came up with the folowing implementation:

        
    //----------------------------------------------------------------------------

    #include <stdio.h>
    #include <string.h>
    #include <windows.h>
    #include <winsock.h>
    //----------------------------------------------------------------------------

    #define SMTP_PORT 25
    #define MAXBUF 4096
    //---------------------------------------------------------------------------

    void send_smtpcmd(SOCKET sock, char *szCmd)
    {
    char szReply[MAXBUF];
    int iLen;
    send(sock, szCmd, strlen(szCmd), 0);
    iLen = recv(sock, szReply, MAXBUF, 0);
    szReply[iLen] = 0;
    printf(szReply);
    }
    //---------------------------------------------------------------------------

    main()
    {

    WORD wVersionRequested = MAKEWORD( 2, 0 );
    WSADATA wsa;
    if (WSAStartup(wVersionRequested , &wsa)!=0)
    { printf("Winsock Initialization failed.\n"); return -1;
    }

    SOCKET sock;
    if ((sock=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET)
    { printf("Can not create socket.\n"); return -1;
    }

    char *szSMTPServer = "www.hotmail.com";
    struct hostent *hs;
    if ((hs=gethostbyname(szSMTPServer))==NULL)
    { printf("Can not resolve specified host.\n"); return -1;
    }
    SOCKADDR_IN addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(SMTP_PORT);
    memcpy((void *)&addr.sin_addr.s_addr, hs->h_addr, hs->h_length);

    if (connect(sock,(LPSOCKADDR)&addr,sizeof(addr))==SOCKET_ERROR)
    { printf("Can not connect to specified host.\n"); return -1;
    }

    char packetbuf[MAXBUF];
    recv(sock, packetbuf, MAXBUF, 0);
    printf("BANNER: %s\n", packetbuf);

    send_smtpcmd(sock, "MAIL FROM: <me@domain.web>\r\n");
    send_smtpcmd(sock, "RCPT TO: <baskuenen@hotmail.com>\r\n"); //can be repeated

    send_smtpcmd(sock, "DATA\r\n");
    send_smtpcmd(sock,
    "Subject: Test HTML mail.\r\n"
    "MIME-Version: 1.0\r\n"
    "Content-Type: text/html; \r\n"
    " charset=\"iso-8859-1\"\r\n"
    "Content-Transfer-Encoding: quoted-printable\r\n"
    ".\r\n");

    closesocket(sock);
    printf("Done.\n");
    return 0;
    }
    //------------------------------------------------------------------------------


    The problem is I get: "Can not connect to specified host."
    There''s something wrong with my connect. But what? I checked the IP-address, and it''s hotmail!
    Is it possible to connect to hotmail? Or must I use my provider orso?

    Help very much respected

    Share this post


    Link to post
    Share on other sites
    Oke - found it - must use my provider address, but I really don't understand why?

    I still dont know how to make good headers (Subject: Content-Type: ...etc...)
    Does anyone know a good link to any lists with possible commands for this?

    Sorry for my stupid questions on this topic I myself must still get used to asking such stupid stupid stupid questions (normally they are only stupid )
    ...He can code a SMTP client, but doesn't know how to connect to the SMTP server...this must be a laugh for some of you...



    Edited by - baskuenen on July 24, 2000 11:26:21 PM

    Share this post


    Link to post
    Share on other sites

    • Advertisement
    ×

    Important Information

    By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

    Participate in the game development conversation and more when you create an account on GameDev.net!

    Sign me up!