Note: the original document is fromHttp://www.vckbase.com/document/viewdoc? Id = 651
Features:ProgramIt is too difficult to compile your own emails!
1. Simple Solution
Use the ShellExecute Function to call the default email program:
ShellExecute (null, null, "mailto: email@163.net", null, null, sw_show );
2. Complicated Solutions
To implement complex functions, such as adding multiple recipients, themes, and attachments, you can call the mapi function of the system. For specific usage, you can check msdn, all of which start with mapi, such as mapilogon and mapisendmail. The following shows how to call the default mail program to send emails. You can add multiple attachments.
Some key issuesCode:
// Mapi must be included. h header file # include "mapi. H "/************************************* * ********************************* Function Name: csendemaildlg: onsendmapi * Description: Call the mapi function to send an email. * Author: Geng * Time: 20:08:30 ************************************** * *****************************/void csendemaildlg:: onsendmapi () {updatedata (true); // load mapi32.dll dynamic library hmodule hmod = loadlibrary ("mapi32.dll"); If (hmod = NULL) {afxmessagebox (callback ); return;} // function address for obtaining the email sending: ulong (Pascal * lpfnsendmail) (ulong, ulong, mapimessage *, flags, ulong); (farproc &) lpfnsendmail = Getprocaddress (hmod, "mapisendmail"); If (lpfnsendmail = NULL) {afxmessagebox (afx_idp_invalid_mapi_dll); return;} int nfilecount = m_list.getcount (); // how many attachments need to be sent // allocate memory to save attachment information cannot use static arrays, because you do not know the number of attachments to be sent mapifiledesc * pfiledesc = (mapifiledesc *) malloc (sizeof (mapifiledesc) * nfilecount); memset (pfiledesc, 0, sizeof (mapifiledesc) * nfilecount); // allocate memory to save the attachment file path tchar * ptchpath = (tchar *) malloc (max_path * Nfilecount); cstring sztext; For (INT I = 0; I <nfilecount; I ++) {tchar * P = ptchpath + max_path * I; m_list.gettext (I, sztext ); strcpy (p, sztext); (pfiledesc + I)-> nposition = (ulong)-1; (pfiledesc + I)-> lpszpathname = P; (pfiledesc + I) -> lpszfilename = P;} // recipient structure information mapirecipdesc recip; memset (& recip, 0, sizeof (mapirecipdesc); recip. lpszaddress = m_szemailmapi.getbuffer (0); recip. ulrecipclass = Mapi_to; // message structure information mapimessage message; memset (& message, 0, sizeof (Message); message. nfilecount = nfilecount; // number of files message. lpfiles = pfiledesc; // file information message. nrecipcount = 1; // number of recipients message. lprecips = & recip; // recipient message. lpszsubject = m_szsubject.getbuffer (0); // subject message. lpsznotetext = m_sztext.getbuffer (0); // body content // Save the window pointer of this program, because after the mail is sent, return the window cwnd * pparentwnd = cwnd: getsafeowner (null, nu Ll); // send the email int nerror = lpfnsendmail (0, 0, & message, mapi_logon_ui | mapi_dialog, 0); If (nerror! = Success_success & nerror! = Mapi_user_abort & nerror! = Mapi_e_login_failure) {afxmessagebox (messages);} // return program pparentwnd-> setactivewindow (); // do not forget to release the allocated memory free (pfiledesc); free (ptchpath ); freelibrary (hmod );}