Jump to content

SMTP.H header

- - - - -

  • Please log in to reply
16 replies to this topic

#1
outsid3r

outsid3r

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 623 posts
Hi all

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.

Attached Files

  • Attached File  smtp.zip   1.23K   132 downloads


#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Very cool outsid3r. I moved this to the Code section rather than the tutorials section though.

#3
Manre

Manre

    Newbie

  • Members
  • Pip
  • 3 posts
Thank you 4 the code.

#4
outsid3r

outsid3r

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 623 posts
I have a new version of this lib, it supports auth login, i will post it here later ;)

#5
Manre

Manre

    Newbie

  • Members
  • Pip
  • 3 posts
That's great, I'll be waiting xD

#6
outsid3r

outsid3r

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 623 posts
Do you need this lib for any project?

#7
Manre

Manre

    Newbie

  • Members
  • Pip
  • 3 posts
No at all, I'm just learning/reading how to use winsock2.h :thumbup1:

#8
outsid3r

outsid3r

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 623 posts
That's great :D

#9
Kraken

Kraken

    Newbie

  • Members
  • Pip
  • 1 posts
Great code. rlly thx

#10
simonfunston

simonfunston

    Newbie

  • Members
  • Pip
  • 1 posts
Helped me out a lot, thanks!

#11
outsid3r

outsid3r

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 623 posts
I forget to finish that lib, there are some things to add and modify... i will finish it later and post it here :D

#12
qwertyuiop123

qwertyuiop123

    Newbie

  • Members
  • PipPip
  • 18 posts
have you added SSL/TLS ? thannks




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users