MFC uses blat to send mail

Download address of blat:
http://www.blat.net

I used it to send mail for smtp service. Here I use the qq mailbox, the password used by the qq mailbox is the authorization code, and the smtp service can be enabled in the qq mailbox settings.
Downloaded is the file directory structure like this:

First, you can register on the machine. To run cmd with the administrator, enter the following command from the cd to blat.exe directory:
blat -install smtp.qq.com [email protected] 3 25 The
specific operations are as follows:

The following is to write the code, mainly to introduce the blatdll.h header file, introduce lib, load blat.dll, get the send method from the dll, and finally send it.

Here #pragma comment (lib, "blat") is to configure the search directory of lib.

It is not possible to load a .dll like a .lib file. I do n’t know what to do, so I use the LoadLibrary () method in the code.
Specific usage:

typedef int(__stdcall*pSend)(LPCSTR sCmd);
	HINSTANCE hdll;
	pSend mySend;
	hdll = LoadLibrary(TEXT("blat32/blat.dll"));
	mySend = (pSend)GetProcAddress(hdll, "Send");
    // mySend(dBuf)

  It should be noted here: typedef int (__ stdcall * pSend) (LPCSTR sCmd); win32 compiled must add __stdcall, otherwise you will not find this method in dll, LPCSTR is const char *, although writing LPCTSTR Match to the method, but the string passed in will be intercepted automatically.

To construct my email message, it is easy to send a verification code here.

CString yzm; 
    yzm.Format (TEXT ( " Verification code:% d " ), m_uYzm); 

    CString cmd2; // = TEXT ("-to [email protected] -subject change password-body '% s' -u 576484879 @ qq.com -pw lakqyyyykfnrbehi -charset utf-8 "); 
    cmd2.Format (TEXT ( " -to [email protected] -subject change password-body% s -u [email protected] -pw authorization code-charset utf-8 " ), yzm);

Here you need to convert CString to char * as follows

wchar_t * sBuf = cmd2.AllocSysString (); 
    DWORD dBufSize = WideCharToMultiByte (CP_OEMCP, 0 , sBuf, -1 , NULL, 0 , NULL, FALSE);
     // allocate target cache 
    char * dBuf = new  char [dBufSize]; 
    memset ( dBuf, 0 , dBufSize); 

    // Convert 
    int nRet = WideCharToMultiByte (CP_OEMCP, 0 , sBuf, -1 , dBuf, dBufSize, NULL, FALSE);

The last is to send
    int x = mySend (dBuf); the
whole is done.

Guess you like

Origin www.cnblogs.com/HelloQLQ/p/12679526.html