program | Send mail
Most of the time you need to send mail in the program, their own make up too troublesome, how to do, oh, there is ready-made!
1, want to save things, with the ShellExecute function:
ShellExecute (Null,null, "mailto:email@263.net", null,null,sw_show);
2, if you want to deal with a number of things, such as the default account number, password, attachment, etc., you can call the system's MAPI function. You can check it out. MSDN starts with MAPI, such as MAPILogon, MAPISendMail, and so on. The following code shows how to invoke the default mail program to send messages.
#include "mapi.h"
void Ctestmapidlg::onsendmail ()
{
Hmodule hmod = LoadLibrary ("MAPI32.") DLL ");
if (Hmod = NULL)
{
AfxMessageBox (Afx_idp_failed_mapi_load);
Return
}
ULONG (PASCAL *lpfnsendmail) (ULONG, ULONG, mapimessage*, FLAGS, ULONG);
(farproc&) Lpfnsendmail = GetProcAddress (Hmod, "MAPISendMail");
if (Lpfnsendmail = NULL)
{
AfxMessageBox (Afx_idp_invalid_mapi_dll);
Return
}
ASSERT (Lpfnsendmail!= NULL);
TCHAR Szpath[_max_path] = "C:\Winnt\setup.log";
TCHAR Sztitle[_max_path] = "Setup.log";
Prepare the file description (for the attachment)
Mapifiledesc Filedesc;
memset (&filedesc, 0, sizeof (FILEDESC));
Filedesc.nposition = (ULONG)-1;
Filedesc.lpszpathname = szpath;
Filedesc.lpszfilename = SzTitle;
Prepare the message (empty with 1 attachment)
MAPIMessage message;
memset (&message, 0, sizeof (message));
Message.nfilecount = 1;
Message.lpfiles = &fileDesc;
int nerror = lpfnsendmail (0, 0,
&message, Mapi_logon_ui¦mapi_dialog, 0);
After returning to the MAPISendMail call, the window must
Being re-enabled and focus returned to the frame to undo the workaround
Done before the MAPI call.
if (nerror!= success_success &&
Nerror!= mapi_user_abort && nerror!= mapi_e_login_failure)
{
AfxMessageBox (Afx_idp_failed_mapi_send);
}
}