Solved

Emailing (alt. to MAPI)

Posted on 1998-10-06
11
438 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

744 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

10 Experts available now in Live!

Get 1:1 Help Now