Recently i started sockets programming with winsock2.h and i decided to build an smpt lib since there is no one by default, and here it is, of course that is still under construction, and later i will make also an lib to pop3 access.
There is an example of a program that sends a mail using smtp protocol.
#include <winsock2.h>
#include <stdio.h>
#include "smtp.h"
int main()
{
WSADATA WSAData;
DWORD WSAResult;
SMTP_MAIL SMTPMail;
SMTP_CLIENT SMTPClient;
WSAResult = WSAStartup(MAKEWORD(2,2), &WSAData);
if(WSAResult)
{
printf("Error loading winsock DLL.\n");
exit(0);
}
else
printf("%s load sucessfully.\n", WSAData.szDescription);
SMTPMail.from = "anyemail@example.com";
SMTPMail.to = "target@mail.com"; // Put your email here
SMTPMail.header = "SMTP mail";
SMTPMail.message = "Here i am!!!";
SMTPClient.port = 25;
SMTPClient.host = gethostbyname("mail.novis.pt");
if(SendSmtpMail(&SMTPClient, &SMTPMail) == SEND_OK)
printf("Mail sended successfully!!\n");
else
printf("Error at sending email...\n");
WSACleanup();
system("pause");
return 0;
}
simple like .NET isn't it?
And also to use winsock2.h for those who dont know, you must add: ws2_32.lib to the linker.


Sign In
Create Account



Back to top









