Adi Drumea

Tuesday, April 15, 2008

[C++] Sending e-mail without SMTP

Today I needed to write some code in a .net application to allow the user to send e-mails with certain files attached to an arbitrary e-mail addresses. The application does not have to depend on Outlook or other e-mail clients being installed on the machine.

I thought about the problem a bit and realized it can be done via DNS queries and sending the mail directly to the domain determined from the recipient's e-mail address (like any MTA does). Fortunately, someone beat me into writing a very simple solution based on ATL.

Here's the link on codeproject:

http://www.codeproject.com/KB/tips/CSMTPConnection2.aspx

I downloaded the source code, basically a derived class overloading CSMTPConnection::Connect to enumerate SMTPs of the given domain, but it did not work. I have Visual Studio 2008 and ATL is no longer included in it. So I downloaded the ATL sources from Microsoft's codeplex:

http://www.codeplex.com/AtlServer

Next, I hit a bug in GetRecipientsString() from atlmime.h, which I have fixed. I then searched the issues on codeplex and found out it was there already:

http://www.codeplex.com/AtlServer/WorkItem/View.aspx?WorkItemId=4683

All I was left to do was to assemble the code in a Managed C++ library and wrap the functionality in a friendly class and my task was done.

0 Comments:

Post a Comment

<< Home