Click here to Skip to main content
15,886,137 members
Articles / Desktop Programming / Win32

SMTP Client

Rate me:
Please Sign up or sign in to vote.
4.82/5 (62 votes)
16 Jul 2010CPOL4 min read 687.5K   22.5K   185  
The CSmtp class allows to send emails with attachments. It only provides the AUTH LOGIN authentication.
#include "CSmtp.h"
#include <conio.h>

int main()
{
	CSmtp mail;
	
	if(mail.GetLastError() != CSMTP_NO_ERROR)
  {
		printf("Unable to initialise winsock2.\n");
		return -1;
	}

	mail.SetSMTPServer("smtp.server.com",25);
	mail.SetLogin("***");
	mail.SetPassword("***");
  mail.SetSenderName("JP");
  mail.SetSenderMail("main@domain.com");
  mail.SetReplyTo("sakla@wp.pl");
  mail.SetSubject("The message test.");
  mail.AddRecipient("friend@gmail.com");
  mail.SetXPriority(XPRIORITY_NORMAL);
  mail.SetXMailer("The Bat! (v3.02) Professional");
  mail.SetMessageBody("This is my message.");
  mail.AddAttachment("c:\\test1.jpg");
  mail.AddAttachment("c:\\test2.exe");
	mail.AddAttachment("c:\\test3.txt");
	
	if( mail.Send() )
		printf("The mail was send successfully.\n");
	else
	{
		printf("%s\n",GetErrorText(mail.GetLastError()));
		printf("Unable to send the mail.\n");
	}

	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer Technical University of Lodz
Poland Poland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions