Click here to Skip to main content
Licence CPOL
First Posted 11 Nov 2009
Views 12,856
Downloads 595
Bookmarked 14 times

Authenticated SMTP

By | 24 Apr 2012 | Article
C++ class to authenticate an SMTP server connection

Introduction

This code is a C++ class derived from the ATL class CSMTPConnection. It adds LOGIN authentication It also allows specifying a custom SMTP port.

Background

The base class is described in detail here.

SMTP negotiating is described here.

Using the Code

Create a Windows project in Visual Studio 2005 and make sure you add ATL support. Create a CAuthSMTPConnection variable and use the Connect method. CMimeMessage is already defined in the ATL libraries and the base class is already set to handle it.

Sample Code

CAuthSMTPConnection SMTP(587,"smtp.server.com","username","password");
if (SMTP.Connect())
{
	// Create the text email message
	CMimeMessage msg;
	msg.SetSubject(csTFTDHdr);
	msg.SetSender("me@somewhere.com");
	msg.SetSenderName("Me");
	msg.AddRecipient("you@somewhere.com");
	msg.AddRecipient("them@somewhere.com");
	msg.AddText("Use CAuthSMTPConnection to authenticate SMTP!");

	// Send the email message
	if (SMTP.SendMessage(msg))
		AfxMessageBox("Sent Mail");
	else
		AfxMessageBox("Mail not sent");
}
else
{
	AfxMessageBox("Can't connect to mail server");
}

History

  • 11/10/09 - Article created
  • 11/11/09 - Cleaned up some insecure code
  • 04/24/12 - Added support for VS2008

License

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

About the Author

Andy Bantly

Founder
GravyLabs LLC
United States United States

Member

Working as a software developer since 1989. Started out with Basic, FORTRAN and JCL, moved into Visual Basic 1.0, C, then C++, and now I work mainly in C++ using MFC, Win32, and ATL/COM. I use Microsoft Products only because that is what gives me gainful employment. Through work, I have a lot of experience with HTML, JavaScript, XSL transformations, the XMLHTTP object, PHP 4.x, and simple COM object integrations.
 
I've worked for the University of Oklahoma in the school of meteorology (Go SOONERS!), consulting, and now as a Senior Software Engineer. These things keep my lights on and electricity going. My dream job is to own a bowling alley and rub elbows with pro-bowlers! I'm also an avid pedicab driver and have my own cab. I like the hustle of picking up people in downtown and biking them to their destination.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmembermaplewang19:44 24 Apr '12  
GeneralMy vote of 1 PinmemberxComaWhitex4:23 24 Apr '12  
GeneralRe: My vote of 1 PinmemberAndy Bantly2:24 25 Apr '12  
GeneralRe: My vote of 1 PinmemberxComaWhitex8:42 25 Apr '12  
Question[My vote of 1] Not an article PinmvpRichard MacCutchan3:14 24 Apr '12  
AnswerRe: [My vote of 1] Not an article PinmemberAndy Bantly3:38 24 Apr '12  
QuestionNow support VS2008 PinmemberAndy Bantly2:12 24 Apr '12  
Questionatlsmtpconnection.h can't get included? PinmemberJoan Murt21:03 23 Apr '12  
AnswerRe: atlsmtpconnection.h can't get included? PinmemberAndy Bantly1:48 24 Apr '12  
GeneralMy vote of 5 Pinmembermaplewang4:02 14 Mar '12  
GeneralMy vote of 1 PinmemberDitecShelby8:04 31 May '11  
GeneralMy Vote is 4 PinmemberAli Sayed7:00 12 Nov '09  
GeneralMy vote of 1 PinassociateJim Crafton5:49 11 Nov '09  
GeneralRe: My vote of 1 PinmemberAndy Bantly6:31 11 Nov '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 24 Apr 2012
Article Copyright 2009 by Andy Bantly
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid