Emailing (alt. to MAPI)

I would like to send an email within my VC++ Win32 app.
It seems MAPI uses Exchange. Is there any classes out there
for emailing?
One which will let me attach a file, and use a proxy?
MAPI seems like it might work if Exchange is set up for
a proxy.. But I'd rather not have to worry about Exchange being set up, on top of my own app.
Who is Participating?
chensuConnect With a Mentor Commented:
Thank you.
Simply use 'ShellExecute()' and supply 'mailto:<recipient>?<subject>' as the 'lpFile' parameter. This will start the default mailer application.
rderidderAuthor Commented:
I would like to send the email --within-- my C++ program.
Is there any classes or such which will let me do this without launching external programs?
I'm doubtfull, but just incase...

Otherwise, I could use the shellexec..or MAPI. Both of these require the default (or Exchange) mailing app. to be configured and setup properly.
I guess one difference between these two methods is that with MAPI I would have to ensure Exchange is runnable on every computer I run my app on, while shellexec just takes the default.

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Yes, that's the problem ... but MAPI also relies on a properly configured MS Exchange...
rderidderAuthor Commented:
The big problem with shellexecute is that the mailing app is executed, and then user interaction is needed. MAPI allows me to send the message automatically.
The app I am making is automated. Emails are sent out without needing user interaction.

i.e: When you register over the net, and the reg. number is sent automatically via email after processing (automatically) to you..How was that email sent do you suppose?
I remember there are SMTP and POP3 classes somewhere in - take a look.
This should do it all for you:
void OnSend()
LHANDLE lhSession = 0;
ULONG ul = 0;

// Compose message
CString csSubject = "Email Test";
CString csText = "\nIt's SO great to be programming today!\n"
"Thank you for your time!\n";

// Load the DLL

HINSTANCE hInstMail = ::LoadLibraryA("MAPI32.DLL");
if(hInstMail == NULL)
ASSERT(hInstMail != NULL);

/* Logon (and Logoff) only needed if a session is not started or
you want to send from a diffrent profile

// Create function pointer to 'MAPILogon' & Logon

(FARPROC &)lpfnLogon = GetProcAddress(hInstMail, "MAPILogon");

lpfnLogon(NULL, "Session", "Password", 0, 0, &lhSession);

// Create function pointer to 'MAPISendMail'

ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage *, FLAGS, ULONG);
(FARPROC &)lpfnSendMail = GetProcAddress(hInstMail, "MAPISendMail");

if(lpfnSendMail == NULL)

// Set up MAPI structs

// Who's sending this email???
MapiRecipDesc MapiFrom;
memset(&MapiFrom, 0, sizeof(MapiFrom));
MapiFrom.ulRecipClass = MAPI_ORIG;
MapiFrom.lpszName = "Big Cheese email sender";
MapiFrom.lpszAddress = "";

// Who gets this email???
MapiRecipDesc MapiTo[2]; // Array of recipiants
memset(&MapiTo[0], 0, sizeof(MapiTo[0]));
MapiTo[0].ulRecipClass = MAPI_TO;
MapiTo[0].lpszName = "Big Cheese email receiver #1";
MapiTo[0].lpszAddress = "";

// Who else gets this email???
memset(&MapiTo[1], 0, sizeof(MapiTo[1]));
MapiTo[1].ulRecipClass = MAPI_TO;
MapiTo[1].lpszName = "Big Cheese email receiver #2";
MapiTo[1].lpszAddress = "";

// Create struct for MAPI to process

MapiMessage Email;
memset(&Email, 0, sizeof(Email));

Email.lpszSubject = csSubject.GetBuffer(csSubject.GetLength());
Email.lpszNoteText = csText.GetBuffer(csText.GetLength());
Email.lpOriginator = &MapiFrom;
Email.lpRecips = MapiTo;      
Email.nRecipCount = 2;      

// Email.flFlags // various
// Email.lpFiles // pointer to 'MapiFileDesc' struct for attachments
// Email.nFileCount

// Call MAPISendMail

ul = lpfnSendMail(lhSession, 0, &Email, 0, 0);
AfxMessageBox("Mail Sent! We're happy!");

/* Logoff (and Logon) only needed if a session is not started or
you want to send from a diffrent profile

// Logoff

// Create function pointer to 'MAPILogoff'
(FARPROC &)lpfnLogoff = GetProcAddress(hInstMail, "MAPILogoff");

ul = lpfnLogoff(lhSession, 0, 0, 0);

if(hInstMail != NULL)

rderidderAuthor Commented:
That looks almost exactly like what I've got. I would like --alternatives to MAPI--.
ie: a SMTP class.

Then maybe I would not be dependent on an Exchange Inbox Profile?

There is one at codeguru, but it doesn't take attachments as yet.

Thanks though..
I would need this info too...
E-Mail file attachment using MIME
rderidderAuthor Commented:
Great stuff! thanks!...

How about I accept an answer from ya chensu?
(Although Wes Clyburn was key as well!)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.