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:winntsetup.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);
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.