Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7196349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:45:40+00:00 2026-05-28T20:45:40+00:00

I have just started learning about socket programming and learned about winsock and achieved

  • 0

I have just started learning about socket programming and learned about winsock and achieved some progress. my question is basically: I want to send emails, what should I do?

points to be mentioned:

  1. I learned about initializing winsock. SMTP port (25). creating and connecting to sockets successfully. What should I do now?!!! (I’m stuck here)
  2. I don’t want a ready-for-work code. I wanna learn. So, any books, documentations, tutorials or articles recommendations are needed.
  3. I know that C itself knows nothing about networking, does that mean I have to download some libraries? (I am using VS2010, Windows 7)

Here are the links to pages I have read so far:

basic winsock guide: http://msdn.microsoft.com/en-us/library/windows/desktop/ms737629(v=vs.85).aspx

I have read the first 14 pages from beej guide (can’t post the link, new users can only post a maximum of two hyperlinks)

I have learned about the types ( WSADATA, addrinfo structure, sockaddr, SOCKET ) and functions ( WSAStartup(), WSACleanup(), getaddrinfo(), Shutdown(), WSAGetLastError(), socket(), … )

and I have just started reading this article about SMTP http://www.faqs.org/rfcs/rfc821.html

here’s what I have written till now:

#include <stdio.h>
#include <WinSock2.h>
#include <WS2tcpip.h>

#pragma comment(lib, "Ws2_32.lib") // Applications that use Winsock must be linked with the Ws2_32.lib library file.

#define HTTP_PORT "80"
#define SMTP_PORT "25"
#define HOSTNAME_PORT "101"

/*
All ports and web services names ( which are string aliases of the ports

 can be found here:
 %WINDIR%\system32\drivers\etc\services

 */

int main(void)
{
    WSADATA wsdata;
    int iresult, retval; //iresult : instant result
    SOCKET connect_socket;
    struct addrinfo *result, *ptr, hints;

    iresult = WSAStartup(MAKEWORD(2, 2), &wsdata);
    if(iresult != 0) printf("Initiation of Winsock succeeded.\n");
    else
    {
        printf("WinSock initialization failed..\n");
        WSACleanup();
        return 0;
    }

    if(LOBYTE(wsdata.wVersion) == 2 && HIBYTE(wsdata.wVersion) == 2) printf("winsock.dll is found.\n");
    else
    {
        printf("Can not find the required winsock.dll file.\n");
        WSACleanup();
        return 0;
    }

    ZeroMemory(&hints, sizeof(hints));
    hints.ai_family = AF_UNSPEC; // IPv4 or IPv6
    hints.ai_protocol = IPPROTO_TCP; // TCP connection ( full duplex )
    hints.ai_socktype = SOCK_STREAM; // Provides sequenced, reliable, two-way, connection-based byte streams

    connect_socket = socket(hints.ai_family, hints.ai_socktype, hints.ai_protocol);
    if(connect_socket == INVALID_SOCKET)
    {
        printf("Socket Creation failed..\n");
        WSACleanup();
        return 0;
    }
    else printf("Socket Creation Succeeded ..\n");
    WSACleanup();
    return 1;
}

am I off course?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:45:42+00:00Added an answer on May 28, 2026 at 8:45 pm

    You should take a look at some examples on smtp via telnet 🙂

    Basically you need to input in plaintext something like this:

    HELO local.domain.name 
    MAIL FROM: mail@domain.ext
    RCPT TO: mail@otherdomain.ext
    DATA
    ...
    

    EDIT according to this example, your code should be:

    // Not sure about this one, maybe just "\n"
    #define  SEPARATOR "\n\r"
    
    int sendData( Socket *socket, const char *data) {
        int iResult;
        iResult = send(socket, data, (int) strlen(data), 0);
        if(iResult == SOCKET_ERROR){
          // Do error handling as you like
        }
        return iResult;
    }
    
    sendData( socket, "HELO local.doman.name" SEPARATOR);
    sendData( socket, "MAIL FROM: mail@domain.ext" SEPARATOR);
    sendData( socket, "RCPT TO: mail@otherdomain.ext" SEPARATOR);
    sendData( socket, "DATA" SEPARATOR);
    sendData( socket, "This is subject of my mail" SEPARATOR SEPARATOR);
    sendData( socket, "And this is text" SEPARATOR);
    sendData( socket, "." SEPARATOR); // Send mail
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have just started learning about xsd as I want to use it
I just started learning about database normalization and I have a question about one
I just started learning C++ and have a question about vectors. The book I'm
Just started learning x64 assembly and I have a question about functions, arguments, and
I have just started learning Erlang and am trying out some Project Euler problems
I'm a real noob who just started learning 3d programming and i have a
I have just started learning java and i have about 8 months time. My
I have just started learning about Android and I was planning on making a
I just started learning about ASP.NET, and I have a couple of questions. Am
Very confused over this. I've just started learning about pointers and have now decided

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.