我这两天写了一个C++的代码,利用MAPI文件中的函数给自己邮箱发一封邮件,但是在发送邮件的时候总是弹出一个警告框,请问怎样设置能在发送邮件的时候不弹出这个警告框而是直接发送,我用的是OutLook2007,请高手指点。
发送邮件的代码如下:
int SendEmail(const char* Address,const char* Subject, const char* Text)
{
int iResult;
UINT iMapiInstalled;
HINSTANCE hMAPIInst;
LPMAPILOGON pMAPILogon;
LPMAPILOGOFF pMAPILogoff;
LPMAPISENDMAIL pMAPISendMail;
LHANDLE lhSession; iResult = SENDEMAIL_SUCCESS; iMapiInstalled = GetProfileInt("Mail", "MAPI", 0); if(! iMapiInstalled)
return SENDEMAIL_MAPI_NOT_INSTALLED; hMAPIInst = LoadLibrary("MAPI32.DLL");
if(!hMAPIInst)
return SENDEMAIL_MAPILOAD_FAILED; pMAPILogon = (LPMAPILOGON)
GetProcAddress(hMAPIInst, "MAPILogon");
pMAPILogoff = (LPMAPILOGOFF)
GetProcAddress(hMAPIInst, "MAPILogoff");
pMAPISendMail = (LPMAPISENDMAIL)
GetProcAddress(hMAPIInst, "MAPISendMail"); if(pMAPILogon(0, NULL, NULL, MAPI_LOGON_UI, 0, &lhSession)
!= SUCCESS_SUCCESS)
{
iResult = SENDEMAIL_LOGON_FAILED;
}
else /* Send the Message */
{
ULONG Result;
MapiMessage Msg; MapiRecipDesc Recipients[1];
Recipients[0].ulReserved = 0;
Recipients[0].ulRecipClass = MAPI_TO;
Recipients[0].lpszName = (char*)Address;
Recipients[0].lpszAddress = (char*)Address;
Recipients[0].ulEIDSize = 0;
Recipients[0].lpEntryID = 0; memset(&Msg, 0, sizeof(Msg));
Msg.lpszSubject = (char*)Subject;
Msg.lpszNoteText = (char*)Text;
Msg.nRecipCount = 1;
Msg.lpRecips = Recipients;// Result = lpfnMAPISendMail(lhSession, 0, &Msg, 0, 0);
Result = pMAPISendMail(lhSession, 1, &Msg, 0, 0);
if(Result != SUCCESS_SUCCESS)
iResult = SENDEMAIL_SEND_FAILED; pMAPILogoff(lhSession, 0, 0, 0);
} FreeLibrary(hMAPIInst); return iResult;
}
发送邮件的代码如下:
int SendEmail(const char* Address,const char* Subject, const char* Text)
{
int iResult;
UINT iMapiInstalled;
HINSTANCE hMAPIInst;
LPMAPILOGON pMAPILogon;
LPMAPILOGOFF pMAPILogoff;
LPMAPISENDMAIL pMAPISendMail;
LHANDLE lhSession; iResult = SENDEMAIL_SUCCESS; iMapiInstalled = GetProfileInt("Mail", "MAPI", 0); if(! iMapiInstalled)
return SENDEMAIL_MAPI_NOT_INSTALLED; hMAPIInst = LoadLibrary("MAPI32.DLL");
if(!hMAPIInst)
return SENDEMAIL_MAPILOAD_FAILED; pMAPILogon = (LPMAPILOGON)
GetProcAddress(hMAPIInst, "MAPILogon");
pMAPILogoff = (LPMAPILOGOFF)
GetProcAddress(hMAPIInst, "MAPILogoff");
pMAPISendMail = (LPMAPISENDMAIL)
GetProcAddress(hMAPIInst, "MAPISendMail"); if(pMAPILogon(0, NULL, NULL, MAPI_LOGON_UI, 0, &lhSession)
!= SUCCESS_SUCCESS)
{
iResult = SENDEMAIL_LOGON_FAILED;
}
else /* Send the Message */
{
ULONG Result;
MapiMessage Msg; MapiRecipDesc Recipients[1];
Recipients[0].ulReserved = 0;
Recipients[0].ulRecipClass = MAPI_TO;
Recipients[0].lpszName = (char*)Address;
Recipients[0].lpszAddress = (char*)Address;
Recipients[0].ulEIDSize = 0;
Recipients[0].lpEntryID = 0; memset(&Msg, 0, sizeof(Msg));
Msg.lpszSubject = (char*)Subject;
Msg.lpszNoteText = (char*)Text;
Msg.nRecipCount = 1;
Msg.lpRecips = Recipients;// Result = lpfnMAPISendMail(lhSession, 0, &Msg, 0, 0);
Result = pMAPISendMail(lhSession, 1, &Msg, 0, 0);
if(Result != SUCCESS_SUCCESS)
iResult = SENDEMAIL_SEND_FAILED; pMAPILogoff(lhSession, 0, 0, 0);
} FreeLibrary(hMAPIInst); return iResult;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货