Solved

Emailing (alt. to MAPI)

Posted on 1998-10-06
11
445 Views
Last Modified: 2012-05-04
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.
0
Comment
Question by:rderidder
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 1174547
Simply use 'ShellExecute()' and supply 'mailto:<recipient>?<subject>' as the 'lpFile' parameter. This will start the default mailer application.
0
 

Author Comment

by:rderidder
ID: 1174548
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.


0
 
LVL 86

Expert Comment

by:jkr
ID: 1174549
Yes, that's the problem ... but MAPI also relies on a properly configured MS Exchange...
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:rderidder
ID: 1174550
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?
0
 
LVL 5

Expert Comment

by:yonat
ID: 1174551
I remember there are SMTP and POP3 classes somewhere in www.codeguru.com - take a look.
0
 
LVL 1

Expert Comment

by:Grailman
ID: 1174552
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)
{
AfxMessageBox(AFX_IDP_FAILED_MAPI_LOAD);
return;
}
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

ULONG (PASCAL *lpfnLogon)(ULONG, LPTSTR, LPTSTR, FLAGS, ULONG, LPLHANDLE);
(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)
{
AfxMessageBox(AFX_IDP_INVALID_MAPI_DLL);
return;
}


////////////////////////////////////////////////////////
// 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 = "SMTP:BigGuy@myprovider.com";

// 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 = "SMTP:otherguy@hisprovider.com";

// 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 = "SMTP:someguy@anotherprovider.com";


////////////////////////////////////////////////////////
// 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);
if(ul == SUCCESS_SUCCESS)
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'
ULONG (PASCAL *lpfnLogoff)(LHANDLE, ULONG, FLAGS, ULONG);
(FARPROC &)lpfnLogoff = GetProcAddress(hInstMail, "MAPILogoff");

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

*/
if(hInstMail != NULL)
::FreeLibrary(hInstMail);
}



0
 

Author Comment

by:rderidder
ID: 1174553
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..
0
 
LVL 8

Expert Comment

by:MaDdUCK
ID: 1174554
I would need this info too...
0
 
LVL 23

Expert Comment

by:chensu
ID: 1174555
E-Mail file attachment using MIME
http://www.codeguru.com/internet/mimemfc.shtml
0
 

Author Comment

by:rderidder
ID: 1174556
Great stuff! thanks!...

How about I accept an answer from ya chensu?
(Although Wes Clyburn was key as well!)
0
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 1174557
Thank you.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

792 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