Solved

Emailing (alt. to MAPI)

Posted on 1998-10-06
11
443 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

821 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