Solved

Send emails from inside a C/C++ program using Microsoft API

Posted on 2008-10-03
3
1,049 Views
Last Modified: 2013-11-30
I'm interested in learning if there is an MFC API for sending SMTP email messages from inside a C/C++ program.

I don't want to use external (3rd party) libraries, as it would be inefficient for my purposes (trying to keep the code small).

Is there a Microsoft supported API for doing this?  I also don't want to require .NET, as the intended audience may be using a Windows 2000 Professional computer that might not have that loaded.
0
Comment
Question by:ttitus
3 Comments
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 250 total points
ID: 22635554
I am not aware of an existing SMTP API interface that is part of MFC however the following articles and their source code might be useful:

SMTP MFC Classes
http://www.codeguru.com/cpp/i-n/internet/email/article.php/c3421

MFC SMTP Email Examples
http://www.example-code.com/mfc/smtp.asp
0
 
LVL 86

Expert Comment

by:jkr
ID: 22635971
Since you refer to a "Microsoft API", I assume you are thinking of MAPI (http://msdn.microsoft.com/en-us/library/245421h5.aspx). Take a look at http://www.codeproject.com/KB/IP/cimapi.aspx ("Another simple MAPI class") - with that, sending a mail can be as simple as
     CIMapi mail;
 

    if (mail.Error() == IMAPI_SUCCESS)

    {

         mail.To("ultramaroon@cox.net");            //  Set recipient name (me)
 

         mail.To("someoneelse@somewhereelse.com");  //  Second recipient
 

         mail.Cc("cc@cc.com");                      //  CC recipient
 

         mail.From("user@somewhere.com");           //  Identify sender (not strictly 
 

                                                    //  necessary since
 

                                                    //  MAPI will fill this in for you)
 

         mail.Subject("Test Email");                //  Subject of this email
 

         mail.Attach("somefilename");               //  Attaching a file
 

         mail.Attach("someotherfile", "different_name_for_recipient");

                                                    // Attach another file but give it
 

                                                    // a different name inside the 
 

                                                    // email itself
 

 

         // Put text of message in body
 

         mail.Text("Body text for this email");     //  Set body text
 

         mail.Send();                               //  Now send the mail! 
 

    }

Open in new window

0
 

Author Comment

by:ttitus
ID: 22690983
MAPI requires a user profile and user mail program, so it's not as useful.  Thanks though!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pre4 challenge 19 94
noX challenge 17 92
wordappend challenge 8 149
JQuery serialize and unserialize 8 51
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now