Call the default email program in the VC to send an email

zhaozj2021-02-17  49

Many times everyone need to send emails in the program, I have a lot of trouble, what to do, huh, huh, there is ready-made!

1. If you want to save things, use the shellexecute function:

Shellexecute (Null, Null, "Mailto: Email@263.net", NULL, NULL, SW_SHOW;

2, if you want to process some things, such as adding the default account, password, attachment, etc., you can call the MAPI function of the system. Specific usage You can check that MSDN is starting with MAPI, such as Mapilogon, MapISendmail et al. The following code demonstrates how to call the default mail program to send an email.

/ / Must include mapi.h header file #include "mapi.h" / ****************************************************** *********************************** * Function Name: csendemaildlg :: OnsendMapi ​​* Description: Call MAPI function send email.

* Author: Geng * Time: 2003-04-22 20:08:30 ********************************* ********************************************* / VOID CSENDEMAILDLG :: OnsendMapi ​​() {Updatedata (TRUE); // load a dynamic library MAPI32.DLL HMODULE hMod = LoadLibrary ( "MAPI32.DLL"); if (hMod == NULL) {AfxMessageBox (AFX_IDP_FAILED_MAPI_LOAD); return;} // send mail acquisition function address 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 saving attachment information that cannot be used, because not knowing the number of attachments to send attachments MAPIFILEDESC * PFILEDESC = (mapifiedesc *) Malloc (SizeOf (mapifileDesc) * nfilecount; MEMSET (pfiledesc, 0, sizeof (mapifiledesc) * nfilecount); // Assign Memory Save Attachment File Path Tchar * PtchPath = (Tchar *) Malloc (Max_Path * Nfile Count; cstring sztext; for (int i = 0; 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;

转载请注明原文地址:https://www.9cbs.com/read-28748.html

New Post(0)